poj 2431 Expedition 优先队列 大顶堆
来源:互联网 发布:淘宝客qq群如何拉人 编辑:程序博客网 时间:2024/05/22 20:21
这题书上说要优先队列,然后看了一下,试着敲了一下,一敲就是这么久
#include<iostream>#include<algorithm>#include<queue>using namespace std;int b[100020];int c[100020];struct point{ int d; int c; friend bool operator<(point a,point b) //重载< 友元函数,而且只能重载<符号 { return a.c<b.c; //大的值在堆上面,用<,否则用>; }}p[100010];bool cmp(point a,point b){ return a.d<b.d;}priority_queue<point>pq;int main(){ int n; cin>>n; int i,j; int x,y; for(i=1;i<=n;i++) { cin>>p[i].d>>p[i].c; } cin>>x>>y; for(i=1;i<=n;i++) { p[i].d=x-p[i].d; } p[0].d=x; p[0].c=0; sort(p,p+n+1,cmp); for(i=n;i;i--) { p[i].d=p[i].d-p[i-1].d; } int pos=0; int ans=0; int tank=y; for(i=0;i<=n;i++) { if(tank<p[i].d) { while(tank<p[i].d) { if(pq.size()==0) { cout<<"-1"<<endl; return 0; } tank+=pq.top().c; ans++; pq.pop(); } } tank-=p[i].d; pq.push(p[i]); } cout<<ans<<endl;}
0 0
- poj 2431 Expedition 优先队列 大顶堆
- poj 2431 Expedition(优先队列)
- poj 2431 Expedition 【优先队列】
- POJ 2431 Expedition 优先队列
- POJ 2431 Expedition(优先队列)
- POJ 2431 Expedition 优先队列
- POJ 2431 Expedition(优先队列)
- Expedition(POJ 2431) 优先队列
- POJ 2431 Expedition (优先队列
- POJ 2431-Expedition(优先队列)
- poj 2431 Expedition 贪心 + 优先队列
- POJ 2431 Expedition (优先队列+贪心)
- POJ 2431 Expedition (贪心 + 优先队列)
- poj 2431 Expedition 贪心 + 优先队列
- 2431Expedition POJ- 优先队列 + 贪心
- poj 2431 Expedition(优先队列)
- poj 2431 Expedition (贪心+优先队列)
- POJ 2431 Expedition (贪心+优先队列)
- const修饰类的成员函数
- 【随笔】未来的路
- JS判断是什么设备是什么浏览器-主要用移动页面开发
- 学习笔记-gitHub使用
- Android Activity 组件生命周期
- poj 2431 Expedition 优先队列 大顶堆
- 数字图像处理02(直方图及均衡化,规定化,局部对比度增强)
- iOS操作小整理
- [HDU 1043] Eight A*或IDA*
- 哈弗曼编码
- TrustZone技术简介
- Ubuntu14.04配置OpenCV3.0的方法
- 引用和指针的区别
- iOS学习之旅之C语言day4