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 ...
随机推荐
- Django部署在CENTOS7上
项目结构 /data/playback_project/├── PlayBack└── script /data/playback_project/PlayBack├── app01├── db.sq ...
- 原生js实现下拉框可输入
js实现下拉框可输入 前言 众所周知,html默认的下拉框是无法输入值的,然后最新的办法是用datalist和输入框绑定,但是很多浏览器不支持.然后还有很多框架提供的下拉框都是可输入的.但是公司的项目 ...
- Linux内核中的static-key机制
# Linux内核中的static-key机制 背景 在移植某个TP时,发现频繁操作屏幕会导致i2c总线死掉.在跟踪代码的时候,我发现了这个static-key. 因此,学习一下这块的知识. refe ...
- arm 移植 lighttpd + CGI 配置
--- title: arm 移植 lighttpd + CGI 配置 EntryName: porting-lighttpd-on-arm-and-make-cgi-config date: 202 ...
- 缺氧debu模式
OxygenNotIncluded_Data(E:\SteamLibrary\steamapps\common\OxygenNotIncluded\OxygenNotIncluded_Data) 文件 ...
- SpringBoot集成日志框架
springboot默认日志是打印在console中,不会保存在文件中.我们项目上线肯定要保存日志用于分析问题的. 使用xml配置日志保存 并不需要pom配置slf4j依赖,starter里面已经配置 ...
- javascript的内存(垃圾)回收机制?
垃圾回收机制 1.js中的内存回收 在js中,垃圾回收器每隔一段时间就会找出那些不再使用的数据,并释放其所占用的内存空间. 以全局变量和局部变量来说,函数中的局部变量在函数执行结束后这些变量已经不再被 ...
- JVM学习笔记-如何在IDEA打印JVM的GC日志信息
若要在Idea上打印JVM相应GC日志,其实只需在Run/Debug Configurations上进行设置即可. 拿<深入Java虚拟机>书中的3-7代码例子来演示,如 1 public ...
- sshd管理限制登录配置(centos7.9)
背景情况:为了公网的主机,被无限的密码爆破,需要对主机的ssh进行安装加固 1.首先要禁用root的远程登录和修改ssh的端口 vi /etc/ssh/sshd_config# 修改端口,不适用22端 ...
- Docker开始收费了,开始转学podman【第一篇podman容器的安装和基本操作】
podman 什么是Podman?Podman是无守护程序容器引擎,用于在Linux系统上开发,管理和运行OCI容器.容器可以以root用户或无根模式运行.简而言之:`alias docker = p ...