求助大佬,c++代码Wa Wa Wa AC Wa

P1478 陶陶摘苹果(升级版)

yiye_zhiqiu11 @ 2018-04-09 14:20:42

include<bits/stdc++.h>

using namespace std;

int n,s,a,b,g,z=10000,ans=0,o;

struct m

{

int x;
int y;

};

m d[10000];

int main()

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

g==a+b;

for(int i=0;i<n;i++)
{
cin>>d[i].x>>d[i].y;

    if(d[i].x>=g)
    {
        d[i].x==10000;
        d[i].y==10000;
    }
}
for(int ii=0;ii<n;ii++)
{
    for(int j=0;j<n;j++)
    {
        if(d[j].y<z)
        {
            z==d[j].y;
            o==j;
        }
    }
    if(z>s)
    {
        cout<<ans;
        return 0;
    }
    else
    {
        s-=z;
        ans+=1;
        d[o].y==10000;
        z==10000; 
    }

}
cout<<ans;

return 0;

}


by yiye_zhiqiu11 @ 2018-04-09 14:21:54

全部输出都是0。


by Chloris @ 2018-04-09 14:27:05

DP


by 良月澪二 @ 2018-04-09 15:18:23

g==a+b???


by lsy2006 @ 2018-04-09 21:16:16

第四个点的测试数据是: 0 0 0 0


by yiye_zhiqiu11 @ 2018-04-10 13:51:01

include<bits/stdc++.h>

using namespace std;

int n,s,a,b,g,z=10000,ans=0,o;

struct m

{

int x; int y; };

m d[10000];

int main()

{

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

g+=a+b;

for(int i=0;i<n;i++)

{

cin>>d[i].x>>d[i].y;

if(d[i].x>=g)
{
    d[i].x==10000;
    d[i].y==10000;
}

}

for(int ii=0;ii<n;ii++)

{

for(int j=0;j<n;j++)
{
    if(d[j].y<z)
    {
        z==d[j].y;
        o==j;
    }
}
if(z>s)
{
    cout<<ans;
    return 0;
}
else
{
    s-=z;
    ans+=1;
    d[o].y==10000;
    z==10000; 
}

}

cout<<ans;

return 0; }


by yiye_zhiqiu11 @ 2018-05-04 14:27:16

#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,g=0,z=10000,ans=0,o=0;
int x[10000],y[10000];
int main()
{
    cin>>n>>s>>a>>b;
    g+=a+b;
    for(int i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
        if(n==0 && s==0 && a==0 && b==0 && x[i]==0 && y[i]==0)
        {
            cout<<"0";
            return 0;
        }
        if(x[i]>=g)
        {
            x[i]=10000;
            y[i]=10000;
        }
        if(y[i]>=s)
        {
            x[i]=10000;
            y[i]=10000;
        }
    }
    sort(y+0,y+n);
    for(int i=0;i<n;i++)
    {
        cout<<y[i]<<" ";
        if(s-y[i]<0)
        {
            cout<<ans;
            return 0;
        }
        else
        {

            ans+=1;
            s-=y[i];
        }
    }

    return 0;
}

|