poj2010解题报告(堆)
来源:互联网 发布:淘宝如何下架宝贝 编辑:程序博客网 时间:2024/06/10 21:45
#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;class tri{ public: int first; int second; int third; bool operator < (const tri temp)const { return first<temp.first; }};bool cmp_p(const tri temp1,const tri temp2){ return temp1.second<temp2.second;}bool cmp(const tri temp1,const tri temp2){ return temp1.second<temp2.second;}int n,c,f,sum_left=0,sum_right=0;bool In_Min_List[110000],Out_Of_List[110000];tri cow[110000],List[110000];int main(){ int i,j,m; scanf("%d%d%d",&n,&c,&f); for(i=1;i<=c;++i) { scanf("%d%d",&cow[i].first,&cow[i].second); } sort(cow+1,cow+c+1); for(i=1;i<=c;++i) { cow[i].third=i; } m=n>>1; j=m; memcpy(List,cow,sizeof(cow)); sort(List+1,List+c-m,cmp_p); for(i=1;i<=m;++i) { In_Min_List[List[i].third]=true; sum_left+=List[i].second; } sort(List+c-m+1,List+c+1,cmp_p); for(i=c-m+1;i<=c;++i) { sum_right+=List[i].second; } make_heap(List+c-m+1,List+c+1,cmp); for(i=c-m;i>=m+1;--i) { if(sum_left+sum_right+cow[i].second<=f) { printf("%d\n",cow[i].first); goto End; } if(In_Min_List[i-1]) { sum_left-=cow[i-1].second; Out_Of_List[i-1]=true; while(Out_Of_List[List[++j].third]); sum_left+=cow[List[j].third].second; In_Min_List[List[j].third]=true; } else { Out_Of_List[i-1]=true; } if(cow[i].second<List[c-m+1].second) { sum_right-=List[c-m+1].second-cow[i].second; pop_heap(List+c-m+1,List+c+1,cmp); List[c]=cow[i]; push_heap(List+c-m+1,List+c+1,cmp); } } printf("-1\n"); End: return 0;}
0 0
- poj2010解题报告(堆)
- 二叉堆例题解题报告代码--poj3253、poj2442、poj2010、poj3481
- 二叉堆模板小结-附上解题报告poj3253、poj2442、poj2010、poj3481
- BZOJ 1455 可并堆(左偏树) 解题报告
- HDU 1512 可并堆(左偏树) 解题报告
- 校内赛 不正常序列 堆 解题报告
- 洛谷 1631 序列合并 堆 解题报告
- poj2010(优先队列)
- poj2010
- poj2010
- poj2010
- POJ2010
- HDU1010(解题报告)
- POJ(解题报告)
- HDU1262(解题报告)
- HDU2028(解题报告)
- (解题报告)HDU1000
- treap——树堆 ( 附pku 2761 解题报告)
- acm比较牛的人的博客 持续更新
- JavaScript权威指南_141_第15章_脚本化文档_15.9-HTML表单-表单和元素的的事件处理程序
- android:ellipsize实现跑马灯效果总结
- Win7下MongoDB的安装和部署测试
- JavaSE初学笔记之<并发编程—内存模型、可见性、原子性>
- poj2010解题报告(堆)
- POJ 2823 Sliding Window(单调队列)
- Ajax初体验之登录校验
- Android 动画之Translate
- hdu 5313 Bipartite Graph 完全二分图 深搜 bitset应用
- JAVA笔记之函数
- SharePoint 2013 搭建负载均衡(NLB)
- Android 动画介绍汇总
- Evaluate Reverse Polish Notation