<NOIP> 26 . P1478 陶陶摘苹果(升级版)
来源:互联网 发布:淘宝买汽车配件 编辑:程序博客网 时间:2024/05/18 03:28
题解:这是洛谷的第26道题目,其实题干就是“最大可以摘到多少苹果”以及“凳子的高度+手臂的长度>=苹果的高度”,还有体力最小为0。
注意
1 . “最大可以摘到多少苹果”提示:需要将每一行的数据按照第二列排列(按照体力的顺序来排列);
2 . 排列完之后,按照上述的规则判断;
源代码:
#include <iostream>#include <stdlib.h>#include <math.h>#include <algorithm>#include <vector>using namespace std;struct MyStruct{ int a; int b;};bool compare(MyStruct A, MyStruct B){ return A.b < B.b;}int main(){ int sum = 0; int apple, strength = 0; int height, length; struct MyStruct number; vector< MyStruct > temp; cin >> apple >> strength; cin >> height >> length; for (long long i = 0; i < apple; i++) { long long a, b; cin >> a >> b; number.a = a; number.b = b; temp.push_back(number); } std::sort(temp.begin(),temp.end(), compare); for (size_t i = 0; i < apple; i++) if (strength >= 0 && strength >= temp.at(i).b) { if (temp[i].a <= length + height) { sum++; strength -= temp[i].b; } } cout << sum << endl; system("pause"); return 0;}
阅读全文
0 0
- <NOIP> 26 . P1478 陶陶摘苹果(升级版)
- P1478 陶陶摘苹果(升级版)
- P1478 陶陶摘苹果(升级版)
- 洛谷P1478 陶陶摘苹果升级版
- |洛谷|贪心|P1478 陶陶摘苹果(升级版)
- luogu【P1478】陶陶摘苹果(升级版)
- luogu P1478 陶陶摘苹果(升级版)
- 洛谷 P1478 陶陶摘苹果(升级版)
- 【模拟】洛谷 P1478 陶陶摘苹果(升级版)
- 洛谷P1478 陶陶摘苹果(升级版,dp)
- 陶陶摘苹果(升级版)
- 陶陶摘苹果(升级版)
- <noip>陶陶摘苹果
- 洛谷1478 陶陶摘苹果(升级版)
- 洛谷1478陶陶摘苹果升级版
- <NOIP> 13 . P1046 陶陶摘苹果
- noip普及组2005 陶陶摘苹果
- 洛谷题解--陶陶摘苹果(升级)
- Nginx搭建
- Sony Xperia Z3+ E6553 开启 VoLTE
- BZOJ 1568: [JSOI2008]Blue Mary开公司 标记永久化
- C3P0配置属性
- Strings Homomorphism
- <NOIP> 26 . P1478 陶陶摘苹果(升级版)
- 二叉搜索树的性质
- JavaSwing_2.2: JButton(按钮)
- LeetCode-415. Add Strings (Java)
- jquery.validate.js表单验证插件使用
- 华为——质数因子_
- Windows上使用压缩包安装MYSQL
- git新建本地库上传到远程库
- 《剑指offer》数值的整数次方