感觉没啥问题啊这代码TAT ,WA了两个

P1478 陶陶摘苹果(升级版)

hunz1 @ 2018-11-22 16:34:54

include <iostream>

using namespace std;

int main() { int n,s,a,b,i; int cnt=0,x,y,t[1001]={0}; cin>>n>>s>>a>>b; for(i=0;i<n;i++) { cin>>x>>y; if(x<=a+b&&y<=s) { t[y]++; } } cnt+=t[0]; for(i=0;i<=s;i++) cout<<"t["<<i<<"]="<<t[i]<<endl; for(i=1;i<=s;i++) { if(s<=0) break; if(t[i]) while(t[i]&&s>0) { s-=i; t[i]--; cnt++; } } cout<<cnt<<endl; }


by hunz1 @ 2018-11-22 16:36:09

#include <iostream>
using namespace std;

int main()
{
    int n,s,a,b,i;
    int cnt=0,x,y,t[1001]={0};
    cin>>n>>s>>a>>b;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x<=a+b&&y<=s)
        {
            t[y]++;
        }
    }
    cnt+=t[0];
    for(i=0;i<=s;i++)
        cout<<"t["<<i<<"]="<<t[i]<<endl;
    for(i=1;i<=s;i++)
    {
        if(s<=0) 
            break;
        if(t[i])
            while(t[i]&&s>0)
            {
                s-=i;
                t[i]--;
                cnt++;
            }
    }
    cout<<cnt<<endl;
}

by sss7020 @ 2018-11-22 16:39:14

for(i=0;i<=s;i++)
    cout<<"t["<<i<<"]="<<t[i]<<endl;

by sss7020 @ 2018-11-22 16:39:22

什么鬼?


by hunz1 @ 2018-11-22 16:46:48

@陈博文1412 这个在编译器调试时候加的,忘删了。


|