Canada Cup 2016 D. Contest Balloons
来源:互联网 发布:js switch case用法 编辑:程序博客网 时间:2024/06/05 02:58
这道题不难,一些细节处理好了就可以了。
主要是把气球数大于自己的插入到set里面,每次更新最小的size就好了。
要注意数据要开long long,还有set里面数据的处理。
#include<bits/stdc++.h>using namespace std;const int maxn = 3e5+5;multiset<long long> ranks;typedef pair<long long,long long> pii;pii num[maxn];bool cmp(pii a,pii b) {return a.first > b.first;}int main() {int n;scanf("%d",&n);long long s,e;int cnt = 0;scanf("%I64d%I64d",&s,&e);for(int i = 0;i < n-1;i++) {long long x,y;scanf("%I64d%I64d",&x,&y);num[cnt].first = x;num[cnt].second = y;cnt++;}sort(num,num+cnt,cmp);int ans = maxn,i = 0;while(1) {while(num[i].first > s && i < cnt) {ranks.insert(num[i].second - num[i].first + 1);i++;}int tt = ranks.size();if(tt < ans)ans = tt;if(tt == 0) break;if(tt > 0) {long long it = *ranks.begin(); //注意这里的写法,错了就RE~//printf("%I64d\n",*it);if(it > s) break;else {ranks.erase(ranks.begin());s -= it;}}}if(ans == maxn) ans = 0;printf("%d\n",ans+1);}
错了很多的小地方,写的时候要细心点,思考全面点。
加油!
0 0
- Canada Cup 2016 D. Contest Balloons
- Canada Cup 2016 D. Contest Balloons
- Canada Cup 2016-D. Contest Balloons(优先队列)
- Canada Cup 2016 D. Contest Balloons (贪心 + 优先队列)
- Canada Cup 2016 D. Contest Balloons(贪心,优先队列)
- [堆 贪心] Canada Cup 2016 D. Contest Balloons
- Canada Cup 2016 D. Contest Balloons 小根堆+贪心
- Canada Cup 2016 D. Contest Balloons详解(贪心+优先队列)
- codeforces Canada cup 2016 A~D
- Canada Cup 2016 D 优先队列
- Canada Cup 2016
- Canada Cup 2016 E
- Canada Cup 2016
- CodeForces Canada Cup 2016【A,B,C,D】
- Canada Cup 2016 A,B,C,D,E
- Canada Cup 2016 C 模拟
- Codeforces 725D Contest Balloons
- codeforces 725D Contest Balloons
- 亲戚【并查集】
- matlab保存figure中的图片去掉白边
- IOS 利用AFN上传图片,支持多张、单张上传
- 安装数据库之2 有些库需要自己下
- 安卓 本地服务和远程服务
- Canada Cup 2016 D. Contest Balloons
- 根据大图获得缩略图
- 2016 Git 教程 从入门到精通(一)
- 使用SOCKET实现TCP/IP协议的通讯
- ccf 炉石传说
- PHP基础——Include、require、include_once、require_once区别。
- 个人微信机器人
- LeetCode ---- Find the Difference (Java/Lua 实现)
- Mac上CocosCreator1.2.1打包andoird apk