社区讨论
求助
题目总版参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo2oluoa
- 此快照首次捕获于
- 2023/10/23 17:14 2 年前
- 此快照最后确认于
- 2023/10/23 17:14 2 年前
陶陶摘苹果III
题目描述
又是一年秋季时,陶陶家的苹果树结了 个果子。陶陶又跑去摘苹果,这次他有一个 公分的椅子。当他手够不着时,他会站到椅子上再试试。
陶陶之前搬凳子,力气只剩下 了。当然,每次摘苹果时都要用一定的力气。陶陶想知道在 之前最多能摘到多少个苹果。
现在已知有 个苹果,陶陶所剩的力气 ,椅子的高度 ,陶陶手伸直的最大长度 ,每个苹果距离地面的高度,陶陶摘一个苹果需要的力气 ,求陶陶最多能摘到多少个苹果。
输入格式
第 行:两个数 苹果数 ,力气 。
第 行:两个数 椅子的高度 ,陶陶手伸直的最大长度 。
第 行~第 行:每行两个数 苹果高度 ,摘这个苹果需要的力气 。
输出格式
只有一个整数,表示陶陶最多能摘到的苹果数。
样例 #1
样例输入 #1
CPP8 15
20 130
120 3
150 2
110 7
180 1
50 8
200 0
140 3
120 2
样例输出 #1
CPP4
提示
对于 的数据,, , , , , 。
我的答案:
CPP#include <iostream>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
#include <string>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
struct tree{
int x,y;
bool operator < (const tree &o) const{
return y<o.y;
}
};
int A[1145140],B[1145140];
int main() {
tree tre;
int n,s,a,b,cnt=0;
cin>>n>>s>>b>>a;
for(int i=0;i<n;i++){
cin>>tre.x>>tre.y;
A[i]=tre.x,B[i]=tre.y;
}
sort(A,A+n);sort(B,B+n);
for(int i=0;i<1145141919810;i++){
if(A[i]<=a+b && B[i]<=s){
s-=B[i];
cnt++;
}
else {
cout<<cnt;
return 0;
}
}
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...