poj2431 Expedition
来源:互联网 发布:java中map集合的用法 编辑:程序博客网 时间:2024/05/22 05:26
直接代码、、、
#include<string.h>#include<stdio.h>#include<queue>#include<iostream>#include<algorithm>using namespace std;struct node{ int fuel,dist; //bool operator < (const node&d) const{ // return dist>d.dist; // }}s[10005];bool cmp(node b,node c){ return b.dist>c.dist;}int main(){ int a,l,p,pos,ans,d,fuels; scanf("%d",&a); priority_queue<int> q; for(int i=0;i<a;i++) { scanf("%d %d\n",&s[i].dist,&s[i].fuel); } sort(s,s+a,cmp);//从大到小进行排序, scanf("%d %d",&l,&p); s[a].dist=0; for(int i=0;i<=a;i++) s[i].dist=l-s[i].dist; fuels=p; ans=0; pos=0; for(int i=0;i<=a;i++) { d=s[i].dist-pos; while(fuels-d<0) { if(q.empty()) { printf("-1\n"); return 0; } fuels+=q.top(); q.pop(); ans++; } fuels-=d; pos=s[i].dist; q.push(s[i].fuel); } printf("%d\n",ans); return 0;}
0 0
- poj2431 Expedition
- POJ2431 Expedition
- poj2431 Expedition
- POJ2431 Expedition
- POJ2431--Expedition
- POJ2431-Expedition
- POJ2431-Expedition
- poj2431 Expedition
- poj2431 Expedition 优先队列
- POJ2431 Expedition (优先队列)
- POJ2431 Expedition(排序+优先队列)
- [POJ2431]Expedition[贪心][优先队列]
- POJ2431-Expedition(优先队列 + 贪心)
- POJ2431 Expedition【贪心+优先队列】
- poj2431 Expedition(优先队列和贪心)
- POJ2431 Expedition (贪心,优先队列)
- POJ2431---Expedition(加油问题,优先队列)
- poj2431 Expedition (优先队列) 挑战程序设计竞赛
- log4j教程及相对路径设置
- 书稿底稿)(C/C++)第一章:CPU基础知识 1.2.2管道技术中的挑战
- 《Linux》天影linux系列笔记一——linux常用命令详解:chown
- C++ 记忆训练游戏
- js中event。keyCode值
- poj2431 Expedition
- activityGroup怎样让子activity中的gridView第一项默认获取焦点?
- EL表达式
- 《Linux》天影linux系列笔记一——linux常用命令详解:mkdir
- 成功解决在Python文件上右键菜单无“Edit with IDLE”选项
- 关于算法的一些知识的介绍
- Cocos2d-html5 更改Loading图片、删除Loading时的小圈圈动画、修改应用名称
- (书稿底稿)(C/C++)第一章:CPU基础知识 1.2.3CORE内核 1.2.4多核概念
- 【剑指offer】员工年龄排序