第三个点RE?

P1478 陶陶摘苹果(升级版)

``` #include<bits/stdc++.h> using namespace std; long long n,a,s,b; struct apple { long long high; long long liqi; }x[99999]; bool cpr(apple x,apple y) { if(x.liqi!=y.liqi) return x.liqi<y.liqi; } int main() { scanf("%lld%lld%lld%lld",&n,&s,&a,&b); a+=b; for(int i=1;i<=n;i++) scanf("%lld%lld",&x[i].high,&x[i].liqi); sort(x+1,x+1+n,cpr); long long S=0; for(int i=1;i<=n;i++) { if(s-x[i].liqi>=0 && x[i].high<=a) { S++; s-=x[i].liqi; } if(s==0) break; } //for(int i=1;i<=n;i++) //printf("%lld %lld\n",x[i].high,x[i].liqi); printf("%lld",S); return 0; } ``` 对不起发错了
by ILXC__SL @ 2018-12-22 17:15:30


@[ILXC](/space/show?uid=79073) 把long long都改成int,数组x开小点,数据里的n小于等于5000,开个10001就够了,然后就可以过了
by 自闭头铁娃 @ 2018-12-22 17:29:43


@[ILXC](/space/show?uid=79073) 诶,等等,我搞错了一点
by 自闭头铁娃 @ 2018-12-22 17:31:55


等下,我把修改的代码发给你
by 自闭头铁娃 @ 2018-12-22 17:32:14


#include<bits/stdc++.h> using namespace std; int n,a,s,b; struct apple { int high;//高度 int liqi;//力气 }x[10001]; int cpr(apple A,apple B)//返回值函数用int比较好 { return A.liqi<B.liqi;//直接按力气大小排序 } int main() { scanf("%d%d%d%d",&n,&s,&a,&b); a+=b; for(int i=1;i<=n;i++) scanf("%d%d",&x[i].high,&x[i].liqi); sort(x+1,x+1+n,cpr); long long S=0; for(int i=1;i<=n;i++) { if(s-x[i].liqi>=0 && x[i].high<=a) { S++; s-=x[i].liqi; } if(s==0) break; } //for(int i=1;i<=n;i++) //printf("%lld %lld\n",x[i].high,x[i].liqi); printf("%d",S); return 0; }
by 自闭头铁娃 @ 2018-12-22 17:35:05


谢谢!
by ILXC__SL @ 2018-12-22 17:36:05



by うちはサスケ @ 2018-12-22 17:50:46


#include<cstdio> #include<algorithm> #include<cstring> #include<vector> #define ms(i,j) memset(i,j, sizeof i); using namespace std; int y[5005]; int main() { int n,s,a,b; scanf("%d%d%d%d", &n ,&s, &a ,&b); int cnt = 0; for (int i=1;i<=n;i++) { int xi,yi; scanf("%d%d", &xi ,&yi); if (a+b>=xi) { y[++cnt] = yi; } } sort(y+1, y+1+cnt); int tot = 0; int ans = 0; for (int i=1;i<=cnt;i++) { if (tot + y[i] <= s) {tot += y[i]; ans++;} else break; } printf("%d\n", ans); return 0; }
by cancanAce @ 2018-12-22 18:08:57


#include<cstdio> #include<algorithm> #include<cstring> #include<vector> #define ms(i,j) memset(i,j, sizeof i); using namespace std; int y[5005]; int main() { int n,s,a,b; scanf("%d%d%d%d", &n ,&s, &a ,&b); int cnt = 0; for (int i=1;i<=n;i++) { int xi,yi; scanf("%d%d", &xi ,&yi); if (a+b>=xi) { y[++cnt] = yi; } } sort(y+1, y+1+cnt); int tot = 0; int ans = 0; for (int i=1;i<=cnt;i++) { if (tot + y[i] <= s) {tot += y[i]; ans++;} else break; } printf("%d\n", ans); return 0; } # ########### # # # # # # # # ~~~~~~~~~~~~~~~~#### ### ## #
by cancanAce @ 2018-12-22 18:09:35


``` #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #define ms(i,j) memset(i,j, sizeof i); using namespace std; int y[5005]; int main() { int n,s,a,b; scanf("%d%d%d%d", &n ,&s, &a ,&b); int cnt = 0; for (int i=1;i<=n;i++) { int xi,yi; scanf("%d%d", &xi ,&yi); if (a+b>=xi) { y[++cnt] = yi; } } sort(y+1, y+1+cnt); int tot = 0; int ans = 0; for (int i=1;i<=cnt;i++) { if (tot + y[i] <= s) {tot += y[i]; ans++;} else break; } printf("%d\n", ans); return 0; } ```
by cancanAce @ 2018-12-22 18:09:55


|