这题很迷啊..

P1478 陶陶摘苹果(升级版)

Misaka_Azusa @ 2018-02-01 08:47:24

include<iostream>

include<cstdio>

include<algorithm>

using namespace std; struct apple{ int h,w; }a[100010]; long long ans=0,n,s,desk,hand,taotao; int cmp(apple a,apple b) { a.w<b.w; } int main() { scanf("%d%d%d%d",&n,&s,&desk,&hand); for(int i=1;i<=n;i++) scanf("%d%d",&a[i].h,&a[i].w);

taotao=desk+hand;
sort(a+1,a+1+n,cmp);

for(int i=1;i<=n;i++)
{
    if(a[i].h<=taotao&&(s-a[i].w)>=0)
    {
        ans++;
        s-=a[i].w;
    }

}

printf("%d",ans);

} 第一次的代码不知道为什么会RE掉

include<iostream>

include<cstdio>

include<algorithm>

using namespace std; int h[50001],w[50001]; int ans=0,n,s,desk,hand,taotao; int main() { cin>>n>>s>>desk>>hand; int k=0,x; taotao=desk+hand; for(int i=1;i<=n;i++) { cin>>h[i]>>x; if(h[i]<=taotao) { w[k]=x; k++; } }

sort(w,w+k);

for(int i=1;i<=k;i++)
{
    if((s-w[i])>=0)
    {
        ans++;
        s-=w[i];
    }
}

cout<<ans;
return 0;

} 第二次的代码连样例都没过就A了?


by zhaomingrui @ 2018-02-01 09:12:47

哪道题啊?


|