2 条题解
-
1
#include<iostream> #include<algorithm> using namespace std; int n,s,a,b,x_,y_,can,rest,ans; struct apple{ int xi,yi; }ap[50005]; int cmp(apple x,apple y){ return x.yi<y.yi; } int main(){ cin>>n>>s>>a>>b; for(int i=1;i<=n;i++){ cin>>x_>>y_; if(x_<=a+b){ can++; ap[can].xi=x_; ap[can].yi=y_; } } sort(ap+1,ap+can+1,cmp); rest=s; ans=0; for(int i=1;rest>=ap[i].yi&&i<=can;i++){ ans++; rest-=ap[i].yi; } cout<<ans; return 0; }
需要排序,利用结构体即可。
-
-3
#include<bits/stdc++.h> using namespace std; int n, s, a, b, x[5010], y[5010], p[5010], i, j, sum; int main() { cin >> n >> s >> a >> b; b += a; for (i = 0; i < n; i ++) { cin >> x[i] >> y[i]; if (x[i] > b)p[i] = 1; } for (i = 0; i < n; i ++) for (j = i + 1; j < n; j ++) if (y[i] > y[j]) { swap(y[i], y[j]); swap(x[i], x[j]); swap(p[i], p[j]); } for (i = 0; i < n; i ++) { if (p[i])continue; if (s >= y[i])s -= y[i], sum ++; } cout << sum << "\n"; return 0; }
- 1
信息
- ID
- 5536
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 2
- 标签
- 递交数
- 98
- 已通过
- 53
- 上传者