自闭了,样例过了,前两个点AC了,第三个第五个WA,第四个RE

P1478 陶陶摘苹果(升级版)

```cpp #include <bits/stdc++.h> using namespace std; int n,s,get,ans,i; struct app { int high,cost; }a[10001]; bool cmp(app x,app y) { // cout<<++i<<" "; return x.cost<y.cost; } int main() { int k,j; cin>>n>>s; cin>>k>>j; get=k+j; for(k=1;k<=n;k++) { cin>>a[k].high>>a[k].cost; if(get<a[k].high||s<a[k].cost) { k--; n--; } } // cout<<n<<endl; // cout<<"KO"<<endl; sort(a+1,a+n+1,cmp); // cout<<"OK"<<endl; for(k=1;k<=n&&s>0;k++) if(s>=a[k].cost) { ans++; s-=a[k].cost; } cout<<ans<<endl; return 0; } ```
by charm1 @ 2019-10-04 22:25:22


@[charm1](/space/show?uid=135258) 可不可以看一下我的代码哪里有错误呢?
by HITACorz @ 2019-10-04 22:34:50


@[JryACtrying](/space/show?uid=52067) 你这个码风跟我不一样,,看不了
by 仗剑_天涯 @ 2019-10-04 22:37:13


@[仗剑走天涯_ZHX](/space/show?uid=223290) 我直接模拟……………………
by HITACorz @ 2019-10-04 22:38:26


别在主函数定义数组
by charm1 @ 2019-10-04 22:42:07


@[仗剑走天涯_ZHX](/space/show?uid=223290) 我的代码太复杂了,不如各位大佬的简介。我是初学者,emm……唉,太难了
by HITACorz @ 2019-10-04 22:42:20


不然洛谷会炸
by charm1 @ 2019-10-04 22:42:25


@[charm1](/space/show?uid=135258) 把数组定义到主函数以外,还是一样的结果两个WA一个RE
by HITACorz @ 2019-10-04 22:44:28


@[JryACtrying](/space/show?uid=52067) 定义全局变量
by charm1 @ 2019-10-04 22:46:58


@[charm1](/space/show?uid=135258) ```cpp #include<iostream> #include<algorithm> using namespace std; const int MAX=5100; struct tt{ int xi;//hight int yi;//strength }; tt tao[MAX]; tt nw[MAX]; bool comparisonxi(tt a,tt b){ return a.xi<b.xi; } bool comparisonyi(tt a,tt b){ return a.yi<b.yi; } int main() { int n,a,s,xi,yi,b; int i; int num=0,temp=0; int k; cin>>n>>s>>a>>b; //scanf("%d%d%d%d",&n,&s,&a,&b); for(i=1;i<n;i++) { cin>>tao[i].xi>>tao[i].yi; // scanf("%d%d",&xi,&yi); } sort(tao+1,tao+n,comparisonxi); for(i=1;i<=n;i++) { if(tao[i].xi<=(a+b)) { nw[i].xi=tao[i].xi; nw[i].yi=tao[i].yi; num++; } else break; } sort(nw+1,nw+num+1,comparisonyi); k=num; for(i=1;i<=num;i++) { if(b>=0&&k>0) { b=b-nw[i].yi; temp++; k--; } else break; } cout<<temp; return 0; } ``` 改成了全局变量还是一样的结果,我哭了……
by HITACorz @ 2019-10-04 22:50:47


| 下一页