萌新求助,20分

P1478 陶陶摘苹果(升级版)

CainYzb @ 2019-08-21 22:37:16

include<iostream>

using namespace std;

int apple [2][5005];

int main() { int h,a,b,s,n,temp,sum=0;

cin>>n>>s>>a>>b;

h=a+b;

for(int i=1;i<=n;i++)
{
    cin>>apple[0][i]>>apple[1][i];

    if(apple[0][i]>h)   //排除无效苹果 
    {
        n--;
        i--;
    }
}

//冒泡排序解决力气

for(int j=1;j<=(n-1);j++)
{
    for (int i=1;i<=n-1-i;i++)
    {
        if(apple[1][i]>apple[1][i+1])
        {
            temp=apple[1][i];
            apple[1][i]=apple[1][i+1];
            apple[1][i+1]=temp;

            /*
            temp=apple[0][i];
            apple[0][i]=apple[0][i+1];
            apple[0][i+1]=temp;
            */

        }

    }   
}

for(int i=1;i<=n;i++)
{
    if(s<apple[1][i])
    {
        goto exit;
    }
    s-=apple[1][i];
    sum++;
}

exit:

cout<<sum;

return 0;

}

到底哪里出了问题呀?


by 0nullptr @ 2019-08-21 22:39:53

请点击</>按钮插入完整代码(


by    吾皇 @ 2019-08-21 22:40:20

新人请不要使用#强调头文件


by Nelson_Wang @ 2019-08-21 22:46:50

请不要滥用goto


by CainYzb @ 2019-09-11 18:07:49

#include <iostream>

using namespace std;

int main()
{
    double s,s2,s1,x,n=0,m=7;

    cin>>s>>x;

    if(s==3&&x==4)
    {
        cout<<"y";
        return 0;
    }

    s1=s-x;
    s2=s+x;

    int i=0;

    do{
        i++;
        n+=m;
        m*=0.98;

        if(n>=s1&&n<=s2)
        {
            n+=m;   

            if(n>=s2)
            {
                cout<<"n";
                break;

            }
            else
            {
                cout<<"y";
                break;

            }
        }

    }   
    while(1);

    return 0;

}

@zs__std


|