POJ 2431 Expedition
2017-07-20 20:32
253 查看
#include<stdio.h> #include<string.h> #include<queue> #include<algorithm> using namespace std; const int maxn = 3e4+5; struct node{ int dis; int fue; bool operator< (const node&I)const { //按照fue由da到xiao排列 return I.fue > fue; } }; bool com (node a, node b){ return a.dis > b.dis; } node a[maxn]; priority_queue <node> pque; int main (){ int n, l, p, tempdis,i,ans; scanf("%d",&n); memset(a,0,sizeof(a)); for (int i = 0; i < n; i++){ scanf("%d%d",&a[i].dis, &a[i].fue ); } sort(a,a+n,com); scanf("%d%d", &l, &p); tempdis = p; i = 0; ans = 0; while (!pque.empty() ) pque.pop() ; while ( tempdis < l){ while ( i < n && a[i].dis >= l - tempdis){ // 符号写反,wa了1晚上... pque.push(a[i]); i++; } if (!pque.empty() ){ tempdis += (pque.top()).fue ; pque.pop() ; ans++; } else break; } if (tempdis >= l){ printf("%d\n",ans); } else printf("-1\n"); }
相关文章推荐
- poj 2431 Expedition 【优先队列】
- POJ 2431 Expedition
- POJ 2431 Expedition
- POJ 2431 Expedition (贪心 + 优先队列)
- POJ 2431 Expedition (优先队列
- poj2431 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
- POJ 2431 Expedition
- POJ 2431 Expedition (汽车加油问题,STL_优先队列+贪心) (挑战程序P76)
- POJ 2431 Expedition【贪心】
- Poj—2431 Expedition 优先队列使用经典例题
- POJ 2431 Expedition (贪心+优先队列)
- POJ 2431 - Expedition (贪心 优先队列)