UVA11367 Full Tank?
优先队列bfs
1 #include<cmath>
2 #include<queue>
3 #include<cstdio>
4 #include<string>
5 #include<cstdlib>
6 #include<cstring>
7 #include<iostream>
8 #include<algorithm>
9 using namespace std;
10 #define rg register
11 typedef long long ll;
12 #define gmax(a,b) a=max(a,b)
13 #define FOR(i,a,b) for(rg int i=a;i<=b;++i)
14 #define qxx(i,a) for(rg int i=fir[a];i;i=nxt[i])
15 #define gc pa==pb&&(pb=(pa=buf)+fread(buf,1,100000,stdin),pa==pb)?EOF:*pa++
16 static char buf[100000],*pa(buf),*pb(buf);
17
18 inline int rd()
19 {
20 rg int x(0),w(1);
21 rg char ch(gc);
22 while(ch<'0' || ch>'9')
23 {
24 if(ch=='-') w=-1;
25 ch=gc;
26 }
27 while(ch>='0' && ch<='9') x=x*10+ch-48,ch=gc;
28 return x*w;
29 }
30
31 const int N=1010,M=10010,C=105,INF=99999999;
32 struct node
33 {
34 int u,cc,co;
35 node(int U,int CC,int CO){u=U;cc=CC;co=CO;}
36 };
37 bool operator < (node x,node y){return x.co>y.co;}
38 int f[N][C];
39 int pr[N],u[M<<1],v[M<<1],w[M<<1],fir[N],nxt[M<<1];
40 int n,m,tot,c,s,e;
41 priority_queue<node> q;
42
43 void bfs()
44 {
45 while(!q.empty()) q.pop();
46 q.push(node(s,0,0));
47 f[s][0]=0;
48 while(!q.empty())
49 {
50 node p=q.top();q.pop();
51 //cout<<p.u<<" "<<p.cc<<" "<<p.co<<endl;
52 if(p.u==e) {cout<<p.co<<endl;return;}
53 if(p.cc<c && p.co+pr[p.u]<f[p.u][p.cc+1])
54 {
55 f[p.u][p.cc+1]=p.co+pr[p.u];
56 q.push(node(p.u,p.cc+1,p.co+pr[p.u]));
57 }
58 qxx(i,p.u)
59 {
60 if(p.cc>=w[i] && f[v[i]][p.cc-w[i]]>=p.co)
61 {
62 f[v[i]][p.cc-w[i]]=p.co;
63 q.push(node(v[i],p.cc-w[i],p.co));
64 }
65 }
66 }
67 cout<<"impossible"<<endl;
68 }
69
70 int main()
71 {
72 n=rd(),m=rd();
73 FOR(i,1,n) pr[i]=rd();
74 while(tot<(m<<1))
75 {
76 u[++tot]=rd(),v[tot]=rd(),w[tot]=rd();
77 ++u[tot],++v[tot];
78 nxt[tot]=fir[u[tot]],fir[u[tot]]=tot;
79 ++tot;u[tot]=v[tot-1],v[tot]=u[tot-1],w[tot]=w[tot-1];
80 nxt[tot]=fir[u[tot]],fir[u[tot]]=tot;
81 }
82 int qq=rd();
83 FOR(i,1,qq)
84 {
85 memset(f,8,sizeof(f));
86 c=rd(),s=rd(),e=rd();
87 ++s,++e;
88 bfs();
89 }
90 return 0;
91 }
UVA11367 Full Tank?的更多相关文章
- UVA11367 Full Tank? 【分层图最短路】
题目 After going through the receipts from your car trip through Europe this summer, you realised that ...
- UVA-11367 Full Tank? (dijkstra)
题目大意:有n个加油站,每个加油站的油价已知,并且已知油箱的大小,问能否从起点走到终点,若能,找出最小油费. 题目分析:记得在做暴力搜索的时候做过这道题,不算难.但是这次是用dijkstra算法做的, ...
- 1.1.1最短路(Floyd、Dijstra、BellmanFord)
转载自hr_whisper大佬的博客 [ 一.Dijkstra 比较详细的迪杰斯特拉算法讲解传送门 Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算 ...
- 最短路算法详解(Dijkstra/SPFA/Floyd)
新的整理版本版的地址见我新博客 http://www.hrwhisper.me/?p=1952 一.Dijkstra Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkst ...
- [ASE]项目介绍及项目跟进——TANK BATTLE·INFINITE
童年的记忆,大概是每周末和小伙伴们围坐在电视机前,在20来寸的电视机屏幕里守卫着这个至今都不知道是什么的白色大鸟. 当年被打爆的坦克数量估计也能绕地球个三两圈了吧. 十几年过去了,游戏从2D-3D,画 ...
- poj3635Full Tank?[分层图最短路]
Full Tank? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7248 Accepted: 2338 Descri ...
- Codeigniter整合Tank Auth权限类库的教程
Codeigniter整合Tank Auth权限类库的教程一开始找了很多CodeIgniter的类库,觉得都不怎么样,后来干脆自己通过CI的钩子系统写了权限管理.但是还是不怎么满意,后来有人推荐tan ...
- poj 3635 Full Tank? ( bfs+dp思想 )
Full Tank? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5857 Accepted: 1920 Descri ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G
Aquarium Tank Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 15 Solved: 4[Submit][Status][Web Board ...
随机推荐
- 使用Scrcpy 在电脑显示手机画面并控制安卓设备
使用Scrcpy 显示手机画面并控制手机 原文(有删改):https://www.iplaysoft.com/scrcpy.html 背景 本文适用于安卓开发人员,不针对普通安卓手机用户. 在安卓开发 ...
- Ubuntu下的NVIDIA显卡【驱动&CUDA 安装与卸载】
碎碎念:主要是把显卡相关的整合出来,基础知识后面再放上来 显卡安装后可以有效降低电脑开太多界面卡顿hhh现象,不过如果显卡不好的话或者是独显的话 问题也不大,主要是学习 learning 使用 参考资 ...
- C#计算两个日期的天数
private int DateDiff(DateTime dateStart, DateTime dateEnd) { DateTime start = Convert.ToDateTime(dat ...
- GAIA: 一个严苛的智能体基准
简要概括 经过一些实验,我们对 Transformers 智能体构建智能体系统的性能印象深刻,因此我们想看看它有多好!我们使用一个 用库构建的代码智能体 在 GAIA 基准上进行测试,这可以说是最困难 ...
- django 中的collectstatic
django 中的collectstatic 在Django中,"collectstatic"是一个管理命令,用于收集和复制项目中的静态文件到一个指定的静态文件目录,以便于部署. ...
- [oeasy]python005_退出游乐场_重启游乐场_系统态shell_应用态_quit
退出终端_重启游乐场_shell_quit Python 回忆 上次 了解了 python 进入了 python 游乐场 在游乐场 可以做 简单的计算 还可以做 乘方运算 数字特别大之后 游乐 ...
- 用ssh同时push 项目到github和gitee的方法
分别为两个网站声称pubkey cd ./ssh ssh-keygen -t rsa -C "oeasy@oeasy.org" -f "github_id_rsa&q ...
- 【VMware VCF】VMware Cloud Foundation Part 02:部署 Cloud Builder。
VMware Cloud Builder 是用于构建 VMware Cloud Foundation 第一个管理域的自动化部署工具,通过将一个预定义信息的 Excel 参数表导入到 Cloud Bui ...
- 单细胞测序最好的教程(九): 细胞类型自动注释|发表在Science的注释算法
作者按 本章节主要讲解了基于大模型的自动注释方法,包括CellTypist(发表在Science)和MetaTiME(发表在Nature communication),一个通用,一个泛癌专用.本教程首 ...
- 简单写写IO流里的一些高级流
缓冲流Buffered:缓冲流是一种高级的流,他可以对file类的流进行包装,内部含有一种缓冲池,可以在一定程度上提高IO的读写效率 不过,按实验来看,只要给低级流和缓冲流相似的byte读写,其实两者 ...