40分跪求神犇们帮助

P1478 陶陶摘苹果(升级版)

@[文文殿下](/space/show?uid=64618) 80分。。。为什么又双叒叕错了呀 ```cpp #include<iostream> #include<algorithm> using namespace std; int n,s,a,b,x,y,i,k[5005],sum=0;//我记得全局变量是初始化为0的。 int main() { cin>>n>>s>>a>>b; a+=b; for(i=1;i<=n;i++) { cin>>x>>y; if(x<=a) k[i]=y; } sort(k+1,k+n+1); for(i=1;i<=n&&(s-k[i])>=0;i++) { if(k[i]==0) continue; s-=k[i]; sum++; } cout<<sum; return 0; } ```
by ihan255 @ 2018-09-05 22:18:00


可能有的k本身就是0, 数据没保证不存在一个果子消耗的体力为0 @[wu55555](/space/show?uid=121281)
by 文文殿下 @ 2018-09-06 02:27:59


@[文文殿下](/space/show?uid=64618) 但我在循环里写了呀 ``` for(i=1;i<=n&&(s-k[i])>=0;i++) { if(k[i]==0) continue; ``` (我是菜鸟,请大神勿怪)
by ihan255 @ 2018-09-08 16:32:51


@[wu55555](/space/show?uid=121281) 有一个果子,摘取的体力花费为0
by 文文殿下 @ 2018-09-09 16:31:00


呜呜,到底怎么改呀
by ihan255 @ 2018-09-29 21:07:49


@[文文殿下](/space/show?uid=64618)
by ihan255 @ 2018-10-05 15:04:47


@[wu55555](/space/show?uid=121281) 已经一个月了啊。。。。 我把我代码给你看吧。。。
by 文文殿下 @ 2018-10-06 19:49:39


```cpp #include<cstdio> #include<algorithm> const int maxn = 5010; int n,s,a,b,y[maxn],tot=0; int main() { scanf("%d%d%d%d",&n,&s,&a,&b); a+=b; for(register int i = 1;i<=n;++i) { int t1,t2; scanf("%d%d",&t1,&t2); if(t1<=a) y[++tot]=t2; } std::sort(y+1,y+1+tot); int ans = 0; for(register int i = 1;i<=tot&&s-y[i]>=0;++i) { ans++; s-=y[i]; } printf("%d",ans); return 0; } ```
by 文文殿下 @ 2018-10-06 19:50:10


上一页 |