UESTC 482 Charitable Exchange(优先队列+bfs)
来源:互联网 发布:各年度网络十大热词 编辑:程序博客网 时间:2024/06/05 07:55
Charitable Exchange
Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Have you ever heard a star charity show called Charitable Exchange? In this show, a famous star starts with a small item which values
In each exchange, one can exchange for an item of Vi yuan if he (she) has an item values more than or equal to
Now, you task is help the star to exchange for an item which values more than or equal to
Input
The first line of the input is
For each case, two integers
Output
For every test case, you should output Case #k:
first, where
Sample input and output
33 105 1 38 2 510 9 24 52 1 13 2 14 3 18 4 15 95 1 110 4 108 1 1011 6 17 3 8
优先队列 贪心+bfs
#include <iostream>#include <string.h>#include <stdlib.h>#include <algorithm>#include <math.h>#include <stdio.h>#include <queue>using namespace std;#define MAX 100000struct Node{long long int v;long long int r;long long int t;}a[MAX+5];struct node{ long long int value; long long int time;bool friend operator <(node a,node b){return a.time>b.time;}};priority_queue<node> q;int n,m;int right1;int cmp(Node a,Node b){ return a.r<b.r;}long long int bfs(){ node term1; term1.value=1;term1.time=0; q.push(term1); int left=1,i; while(!q.empty()) {node term2=q.top(); q.pop(); if(term2.value>=m) { return term2.time; }for(i=left;i<=right1;i++) { if(term2.value>=a[i].r&&term2.value<a[i].v) { node temp; temp.value=a[i].v; temp.time=term2.time+a[i].t;q.push(temp); }if(term2.value<a[i].r)break; }left=i; }return -1;}int main(){ int t; int cas=0; scanf("%d",&t); long long int vv,rr,tt; while(t--) { scanf("%d%d",&n,&m); right1=0; for(int i=1;i<=n;i++) { scanf("%lld%lld%lld",&vv,&rr,&tt); if(vv==rr) continue; a[++right1].v=vv;a[right1].r=rr;a[right1].t=tt; }while(!q.empty())q.pop(); sort(a+1,a+1+right1,cmp); printf("Case #%d: %lld\n",++cas,bfs()); } return 0;}
Case #1: -1Case #2: 4Case #3: 10
- UESTC 482 Charitable Exchange(优先队列+bfs)
- uestc 482 Charitable Exchange 广搜+优先队列优化
- UESTC 482 Charitable Exchange
- 四川省ACM省赛B题,优先队列+BFS Charitable Exchange
- UESTC 482 Charitable Exchange (线段树)
- UESTC 1558 Charitable Exchange
- UESTC 1558 Charitable Exchange
- UESTC 482 Charitable Exchange(四川省赛B题)
- 最短路,前缀和优化连边,Dijkstra(UESTC 482,Charitable Exchange)
- *【UESTC】优先队列
- UESTC 1599 wtmsb 优先队列(最小值优先)
- 优先队列+BFS
- hdu1242优先队列BFS
- HDU4198-BFS+优先队列
- acmdream1191 bfs+优先队列
- Hdu2822Dogs bfs+优先队列
- hdu4198-优先队列+bfs
- BFS+队列优先
- CSS3选择器详解二
- Bagging, Boosting, and Randomization对比
- [BZOJ3333]排队计划(离散化+树状数组+线段树)
- ios 微信分享,QQ分享,微博分享集成
- 第2章 分支出12章 第1章汇编概念
- UESTC 482 Charitable Exchange(优先队列+bfs)
- HDU 1166
- LoadRunner 问题总结
- target not be null
- Android笔记 Activity和Service的通信
- PowerDesigner使用之设计数据库
- 图解Windows下QT编程入门
- android studio配置OpenCV
- Python-OpenCV 杂项(一):图像绘制