poj 2431 Expedition 贪心
来源:互联网 发布:淘宝网广告形式 编辑:程序博客网 时间:2024/05/17 08:33
简单的说说思路,如果一开始能够去到目的地那么当然不需要加油,否则肯定选择能够够着的油量最大的加油站加油,,不断重复这个贪心的策略即可。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;const int maxn=1e4+9;int dist,p,n;struct S{ int d,f; bool operator <(const S & xx) const { return d<xx.d; }}stop[maxn];struct cmp{ bool operator ()(const S &a,const S &b) const { return a.f<b.f; }};int main(){ while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) scanf("%d %d",&stop[i].d,&stop[i].f); scanf("%d %d",&dist,&p); for(int i=1;i<=n;i++) stop[i].d=dist-stop[i].d; sort(stop+1,stop+1+n); int ans=0,t=1; bool flag=true; priority_queue <S,vector<S>,cmp> q; while(p<dist) { while(t<=n&&stop[t].d<=p) q.push(stop[t++]); if(q.empty()) { flag=false; break; } ans++; p+=q.top().f; q.pop(); } if(flag) cout<<ans<<endl; else cout<<-1<<endl; } return 0;}
- poj 2431 Expedition 贪心
- POJ 2431 Expedition【贪心】
- POJ 2431 - Expedition(贪心)
- 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 (贪心 + 优先级队列)
- POJ 2431 Expedition (贪心、优先队列)
- poj 2431 Expedition 贪心 + 优先队列
- poj 2431Expedition(优先队列+贪心)
- poj,2431Expedition 贪心 + 优先队列
- POJ 2431 Expedition (贪心、优先队列)
- 结构体 struct{} 和 typedef struct{}
- apache配置文件中 设置访问日志不记录 指定ip的访问记录
- MongoDB命令行操作(上)
- shell expect使用方法
- COM套间
- poj 2431 Expedition 贪心
- 教你如何写简历找工作
- DTD和schema的优缺点
- 第一章~第一节spring bean的生命周期
- IOS几种简单有效的数组排序方法
- import maven projects 卡死,抛出GC overhead limit exceeded
- autolayout自动布局详解
- 设计模式之(三)Proxy模式
- 判断字符串是否为布尔型、浮点型、整型...