给你n个物品交换,每个交换用r,v,t描述,代表需要用r元的东西花费t时间交换得v元的东西。一开始只有1元的东西,让你求出交换到价值至少为m的最少时间代价。
相当于每个交换是一条边,时间为边权,求走到价值大于等于m的点的最短路径。
bfs的时候,用优先队列来储存状态,每次取出花费总时间最小的状态。

#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std; struct node{
int r,v;
ll t;
}a[]; int n,m,cas; int cmp(const node &a, const node &b){
return a.r<b.r;
} struct cmp2{
bool operator ()(const node &a, const node &b)
{
return a.t>b.t;
}
}; priority_queue<node, vector<node>, cmp2>q; ll bfs(){
int l=,i;
q.push((node){,,}); while(!q.empty()){
node s=q.top();
q.pop(); if(s.v>=m)
return s.t; for(i=l;i<=n;i++){
if(s.v>=a[i].r&&s.v<a[i].v)
q.push((node){,a[i].v,s.t+a[i].t});
if(s.v<a[i].r)
break;
} l=i;
}
return -;
} int main(){
scanf("%d",&cas);
for(int c=;c<=cas;c++){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d%d%d",&a[i].v,&a[i].r,&a[i].t); while(!q.empty())q.pop();
sort(a+,a++n,cmp); printf("Case #%d: %lld\n",c,bfs());
}
return ;
}

  

【UESTC 482】Charitable Exchange(优先队列+bfs)的更多相关文章

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

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

  2. CDOJ 482 Charitable Exchange bfs

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

  3. cdoj 482 优先队列+bfs

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

  4. hdu 1026 Ignatius and the Princess I【优先队列+BFS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1026 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  5. ZOJ 649 Rescue(优先队列+bfs)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  6. 【POJ3635】Full Tank 优先队列BFS

    普通BFS:每个状态只访问一次,第一次入队时即为该状态对应的最优解. 优先队列BFS:每个状态可能被更新多次,入队多次,但是只会扩展一次,每次出队时即为改状态对应的最优解. 且对于优先队列BFS来说, ...

  7. Codeforces 677D - Vanya and Treasure - [DP+优先队列BFS]

    题目链接:http://codeforces.com/problemset/problem/677/D 题意: 有 $n \times m$ 的网格,每个网格上有一个棋子,棋子种类为 $t[i][j] ...

  8. POJ 2449 - Remmarguts' Date - [第k短路模板题][优先队列BFS]

    题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good m ...

  9. hdu - 1242 Rescue && hdu - 2425 Hiking Trip (优先队列+bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了 ...

随机推荐

  1. 《至少有那天》——IU

    //<你的意义>中文版 那天冷的让人好想哭 可是我那一天看到了爱情 湖边的薄冰和老树 就在零下七度那一天 你和我牵手 慢慢聊着以前那些童话 可能它们都有些意义吧 是吗 一个吻 一滴眼泪 一 ...

  2. scp: command not found如何解决

    今天给一台新的服务器,准备源码安装一些软件,需要使用scp复制文件时报错如下:-bash: scp: command not found 解决办法如下:安装scp的软件包:# yum install ...

  3. throw跟throws关键字

    throws关键字 定义一个方法的时候可以使用throws关键字声明.使用throws关键字声明的方法表示此方法不处理异常,而交给方法调用处进行处理. throws关键字格式: public 返回值类 ...

  4. GitLab/Git在AndroidStudio上的使用(转)

    1.在AndroidStudio上的配置GitLab 1)首先先将gitlab上的开发项目clone到本地(可以使用命令行或者管理工具,具体操作在GitLab中已经涉及,这里不再赘述),然后导入到An ...

  5. [IPSEC PKI]

    PKI: 对称加密 非对称加密(混合加密) 数字签名   理论概述: (1)预备知识 对称加密:加密密钥和揭秘蜜钥是同一个密钥 缺点:不适合在互联网上传输密钥 密钥维护工作量大 n(n-1)/2 : ...

  6. 装了个干净的win7

    lanny的电脑基本信息 我的电脑 联想 ThinkPad T450s 笔记本电脑 操作系统 Windows 旗舰版 64位 主显卡 集成显卡 IE浏览器 版本号 8.0 基本硬件展示 处理器 英特尔 ...

  7. android camera setParameters failed 类问题分析总结

    在 monkey test 测试中出现了一例 RuntimeException ,即 setParameters failed. LOG显示为:09-01 18:47:17.348 15656 156 ...

  8. 本地环境,Ecshop安装教程

    最近有个项目需要用ECshop来做,之前没接触过ECshop,今天去网上找了下安装教程,现在发出来分享一下. 1. ecshop网店系统最新版本是ECSHOP V2.7.3,去官网下载utf8和gbk ...

  9. (OAF)jdeveloper集成log4j并将日志输出到指定文件并写入数据库

    参考: How to configure Log4j in JDev 11g Ever wanted to use log4j in your adf project ? Well though Or ...

  10. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习

    # Practice Exercises for Functions # Solve each of the practice exercises below. # 1.Write a Python ...