#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue> using namespace std; typedef long long LL;
const int maxn = 1e5+;
int T,N,cnt;
LL M; struct node{
LL money,time;
node(){}
node(LL a,LL b){money=a;time=b;}
bool operator < (const node &b) const
{return time > b.time;}
}; struct item
{
LL V,R,time;
item(){}
item(LL a,LL b,LL c){V = a;R = b;time = c;}
bool operator < (const item &b) const
{return R < b.R;}
}items[maxn]; LL bfs()
{
priority_queue<node> pq;
node st(,),cur;
pq.push(st);
int i,x=;
while(!pq.empty())
{
cur = pq.top();pq.pop();
if(cur.money >= M) return cur.time;
for(i=x;i<=cnt;i++)
{
if(cur.money < items[i].R) break;
if(cur.money>=items[i].R&&cur.money<items[i].V)
{
pq.push(node(items[i].V,cur.time+items[i].time));
}
}
x = i;
}
return -;
} int main()
{
cin >> T;
for(int cas=;cas<=T;cas++)
{
cin >> N >> M;
LL v,r,t;
cnt=;
for(int i=;i<N;i++)
{
cin >> v >> r >> t;
if(v==r) continue;
items[cnt++] = item(v,r,t);
}
sort(items+,items+cnt+);
cout << "Case #"<<cas<<": "<<bfs()<<endl;
}
}

UESTC482-Charitable Exchange-bfs优先队列的更多相关文章

  1. CDOJ 482 Charitable Exchange bfs

    Charitable Exchange Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/s ...

  2. 【UESTC 482】Charitable Exchange(优先队列+bfs)

    给你n个物品交换,每个交换用r,v,t描述,代表需要用r元的东西花费t时间交换得v元的东西.一开始只有1元的东西,让你求出交换到价值至少为m的最少时间代价.相当于每个交换是一条边,时间为边权,求走到价 ...

  3. UESTC 482 Charitable Exchange(优先队列+bfs)

    Charitable Exchange Time Limit: 4000/2000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Othe ...

  4. POJ 1724 ROADS(BFS+优先队列)

    题目链接 题意 : 求从1城市到n城市的最短路.但是每条路有两个属性,一个是路长,一个是花费.要求在花费为K内,找到最短路. 思路 :这个题好像有很多种做法,我用了BFS+优先队列.崔老师真是千年不变 ...

  5. hdu 1242 找到朋友最短的时间 (BFS+优先队列)

    找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.... ...

  6. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

  7. hdu1839(二分+优先队列,bfs+优先队列与spfa的区别)

    题意:有n个点,标号为点1到点n,每条路有两个属性,一个是经过经过这条路要的时间,一个是这条可以承受的容量.现在给出n个点,m条边,时间t:需要求在时间t的范围内,从点1到点n可以承受的最大容量... ...

  8. BFS+优先队列+状态压缩DP+TSP

    http://acm.hdu.edu.cn/showproblem.php?pid=4568 Hunter Time Limit: 2000/1000 MS (Java/Others)    Memo ...

  9. POJ - 2312 Battle City BFS+优先队列

    Battle City Many of us had played the game "Battle city" in our childhood, and some people ...

  10. HDU 1242 -Rescue (双向BFS)&amp;&amp;( BFS+优先队列)

    题目链接:Rescue 进度落下的太多了,哎╮(╯▽╰)╭,渣渣我总是埋怨进度比别人慢...为什么不试着改变一下捏.... 開始以为是水题,想敲一下练手的,后来发现并非一个简单的搜索题,BFS做肯定出 ...

随机推荐

  1. mongo中的模糊查询

    以下是一个mongo查询的综合应用,即介绍一个生产中实际应用的模糊查询,当然其实也很简单,主要用到mongo中的模糊查询和$or查询,以及并的关系,下面是一个mongo中的一条记录 { "_ ...

  2. Windows 10 配置Linux及安装Docker

    https://baijiahao.baidu.com/s?id=1607159570058814753&wfr=spider&for=pc https://blog.csdn.net ...

  3. 微软Azure AspNetCore微服务实战第1期【补充2017-09-09活动】

    2017年09月09日,冒着酷暑,我们在(上海徐汇)虹桥路3号港汇中心2座10层组织了一次微软Azure AspNetCore微服务实战活动. 由于前期工作繁忙,活动完成之后,没能及时发布相关信息,特 ...

  4. sczd

  5. C#跨进程读取listview控件中的数据

    http://www.cnblogs.com/Charltsing/p/slv32.html 欢迎交流:QQ564955427 读取标准的32位listview控件中的数据,网上已经有很多代码了.今天 ...

  6. WebSocket实现一个聊天室

    聊天室页面-->index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...

  7. nmon for Linux & Java

    nmon for Linux | Main / HomePagehttp://nmon.sourceforge.net/pmwiki.php Java Nmon Analyser download | ...

  8. [转帖]前端-chromeF12 谷歌开发者工具详解 Console篇

    前端-chromeF12 谷歌开发者工具详解 Console篇 https://blog.csdn.net/qq_39892932/article/details/82655866 趁着搞 cloud ...

  9. PL/SQL编程--变量声明及赋值

    declare v_price ,);--单价 v_usenum number;--水费字数 v_usenum2 number;--使用吨数 begin v_price:=2.45;--每吨单价 v_ ...

  10. easyUI定区关联快递员js代码

    easyUI定区关联快递员js代码: <script type="text/javascript"> $.fn.serializeJson=function(){ va ...