【贪心+堆】Codeforces 752D Contest Balloons
来源:互联网 发布:淘宝网大码女装夏装 编辑:程序博客网 时间:2024/06/05 02:59
题面在这里
显然每次只要给排名比自己大的人送气球
那么肯定选需要最小气球的人来猥琐他
然后更新一下排名比自己大的人的集合就好了
示例程序:
#include<cstdio>#include<queue>#include<algorithm>#define LL long longusing namespace std;const int maxn=300005;int n;struct data{ LL t,w; data () {} data (LL _t,LL _w):t(_t),w(_w) {} bool operator<(const data&b)const{ return t<b.t; } LL v()const {return w-t+1;}}a;struct cmp{ bool operator()(data&a,data&b){ return a.w-a.t>b.w-b.t; }};priority_queue<data,vector<data>,cmp> A;priority_queue<data> B;int main(){ scanf("%d",&n); scanf("%lld%lld",&a.t,&a.w); for (int i=2;i<=n;i++){ LL t,w; scanf("%lld%lld",&t,&w); if (t>a.t) A.push(data(t,w));else B.push(data(t,w)); } int ans=A.size()+1; while (!A.empty() && a.t>=A.top().v()){ a.t-=(A.top()).v(); A.pop(); while (!B.empty() && B.top().t>a.t) A.push(B.top()),B.pop(); ans=min(ans,(int)A.size()+1); } printf("%d",ans); return 0;}
阅读全文
2 0
- 【贪心+堆】Codeforces 752D Contest Balloons
- Codeforces 725D[Contest Balloons]【贪心】
- [堆 贪心] Canada Cup 2016 D. Contest Balloons
- codeforces 725D Contest Balloons(贪心+优先队列)
- Codeforces 725D Contest Balloons
- codeforces 725D Contest Balloons
- Codeforces 725D Contest Balloons
- 【贪心+堆】Codeforces725D[Contest Balloons]题解
- 【37.74%】【codeforces 725D】Contest Balloons
- codeforces 725D Conteset Balloons 贪心
- Canada Cup 2016 D. Contest Balloons (贪心 + 优先队列)
- Canada Cup 2016 D. Contest Balloons(贪心,优先队列)
- Canada Cup 2016 D. Contest Balloons 小根堆+贪心
- codeforce 725D Contest Balloons
- Canada Cup 2016 D. Contest Balloons详解(贪心+优先队列)
- Gym 100231D Balloons 贪心
- Canada Cup 2016 D. Contest Balloons
- Canada Cup 2016 D. Contest Balloons
- dfs 解二维背包
- Hadoop详解(四)——Shuffle原理,Partitioner分区原理,Combiner编程,常见的MR算法
- Centos学习之vi/vim编辑器
- 脏读和READ UNCOMMITED隔离级别
- js在线文档
- 【贪心+堆】Codeforces 752D Contest Balloons
- eclipes设置编码格式
- yii php ajaxUpload上传图片以及post提交记住已填信息
- Linux重装Mysql
- JSP总结
- 前端面试系列(一):网站优化的解决方案
- 版本控制SVN(二 安装)
- 点我达分布式任务调度系统
- 【BZOJ】1150 [CTSC2007]数据备份Backup 堆+链表