The Toll! Revisited UVA - 10537(变形。。)
给定图G=(V,E)G=(V,E),VV中有两类点,一类点(AA类)在进入时要缴纳1的费用,另一类点(BB类)在进入时要缴纳当前携带金额的1/20(不足20的部分按20算)
已知起点为SS,终点为TT,希望在到达TT时能够拥有PP的金额,问一开始在SS最少要携带多少金额,并求出路径(若有多条,输出字典序最小的)
从SS离开时不需要缴费,进入TT时需要缴费
倒序找最短路 d[i] 表示从i到终点需要的最少的金额 在更新d的时候 分两种情况
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = ;
const long long Inf = (1LL<<);
int head[N];
int vis[];
int cnt;
char to[];
int n, m;
long long d[N];
bool inq[N];
int p[N];
struct Edge{
int v, w, next;
}edges[N*]; void add(int u ,int v, int w)
{
edges[cnt].v = v;
edges[cnt].w = w;
edges[cnt].next = head[u];
head[u] = cnt++;
} void init()
{
memset(head, -, sizeof(head));
cnt = ;
} void print(int u){
if( p[u]==- ){
printf("%c\n", to[u] );
return ;
}
printf("%c-", to[u] );
print(p[u]);
}
void spfa(int s, long long vl){
for ( int i=; i<N; i++ ) d[i]=Inf, inq[i]=;
d[s]=vl;
p[s]=-;
queue<int> Q;
Q.push(s);
while( !Q.empty() ){
int u=Q.front(); Q.pop();
inq[u]=;
for ( int i=head[u]; i!=-; i=edges[i].next ){
Edge e=edges[i];
long long nd;
if(e.w) nd=(long long) ceil(d[u]*1.0/*); //推一下公式。。虽然我没推出来
else nd=d[u]+;
if( d[e.v]>nd || d[e.v]==nd && to[u]<to[p[e.v]] ){ //如果相等 则判断字典序
d[e.v]=nd;
p[e.v]=u;
if( !inq[e.v] ){
inq[e.v]=;
Q.push(e.v);
}
}
}
}
} int main(){
for ( int i=; i<; i++ ) {
vis['a'+i]=i+; to[i+]='a'+i;
vis['A'+i]=i; to[i]='A'+i;
}
int n, m, kas=;
while( scanf("%d", &m ) == && m!=- ){
init();
char a[], b[];
for ( int i=; i<=m; i++ ){
scanf("%s%s", a, b );
int u=vis[a[]], v=vis[b[]];
add(u,v,a[]<'a');
add(v,u,b[]<'a');
}
long long vl;
scanf("%lld%s%s", &vl, a, b );
int u=vis[a[]], v=vis[b[]];
spfa(v,vl);
printf("Case %d:\n", ++kas);
printf("%lld\n", d[u]);
print(u);
}
}
The Toll! Revisited UVA - 10537(变形。。)的更多相关文章
- 【Toll!Revisited(uva 10537)】
题目来源:蓝皮书P331 ·这道题使得我们更加深刻的去理解Dijkstra! 在做惯了if(dis[u]+w<dis[v])的普通最短路后,这道选择路径方案不是简单的比大小的题横在了 ...
- uva 10537 Toll! Revisited(优先队列优化dijstra及变形)
Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母. 首先输入m条边.当经过小写字母时须要付一单位的过路费.当经过大写字母时,要付当前財务的1/20做过路费. 问在起 ...
- UVA 10537 - The Toll! Revisited(dijstra扩张)
UVA 10537 - The Toll! Revisited option=com_onlinejudge&Itemid=8&page=show_problem&catego ...
- UVA10537 Toll! Revisited
difkstra + 路径输出 The Toll! Revisited Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- UVA 10537 The Toll! Revisited 过路费(最短路,经典变形)
题意:给一个无向图,要从起点s运送一批货物到达终点e,每个点代表城镇/乡村,经过城镇需要留下(num+19)/20的货物,而经过乡村只需要1货物即可.现在如果要让p货物到达e,那么从起点出发最少要准备 ...
- UVA 10537 The Toll! Revisited uva1027 Toll(最短路+数学坑)
前者之所以叫加强版,就是把uva1027改编了,附加上打印路径罢了. 03年的final题哦!!虽然是水题,但不是我这个只会做图论题的跛子能轻易尝试的——因为有个数学坑. 题意:运送x个货物从a-&g ...
- UVa 10537 The Toll! Revisited (最短路)
题意:给定一个图,你要从 s 到达 t,当经过大写字母时,要交 ceil(x /20)的税,如果经过小写字母,那么交 1的税,问你到达 t 后还剩下 c 的,那么最少要带多少,并输出一个解,如果多个解 ...
- UVA 10537 Toll! Revisited (逆推,最短路)
从终点逆推,d[u]表示进入u以后剩下的货物,那么进入u之前的货物数量设为y,d[u] = x,那么y-x=ceil(y/20.0)=(y-1)/20+1=(y+19)/20. (y-x)*20+r= ...
- Uva 10537 过路费
题目链接:http://vjudge.net/contest/143062#problem/C 题意: 给定一个无向图,大写字母是城市,小写字母是村庄,经过城市交过路费为当前货物的%5,路过村庄固定交 ...
随机推荐
- day 3 局部变量 全局变量
1.局部变量 2.全局变量(死歌的大招)函数前面声明的都是全局变量 3.全局变量和局部变量的区别 1)老方法 def get_temper(): temper = 33 return temper d ...
- MSP430FR6972的串口波特率设置代码
1. 本次使用ACLK,就是辅助时钟(32.768KHZ)作为串口的时钟源,那么使用波特率9600的时候,分频系数=32768/9600=3.41,所以是有小数位的,设置代码如下 UCA0CTLW0 ...
- jaron插件的用法
一.dict字典插件的基本用法: <%@ taglib prefix="dict" uri="http://www.evan.jaron.com/tags/dict ...
- nginx 反向代理到目录
upstream yg{ server 127.0.0.x; } server { listen 80; server_name www.hikaru.pw; location / { rewrite ...
- LUA对象
Rectangle = {width = , height = , area = }; function Rectangle:new(o, width, height) o = o or {}; se ...
- linux安装PHP-memcache-redis扩展
1.php memcache 扩展 http://pecl.php.net/package/memcache/3.0.8 下载文件源码 #tar zxvf memcache-3.0.8.tar#/us ...
- 牛客小白月赛9 A签到(分数取模,逆元)
传送门 对分母求一下逆元,把除法取模变成乘法取模,逆元介绍看这里 这种方法只适合模为质数的情况 #include<bits/stdc++.h> using namespace std; ; ...
- Testing Harbor REST API on Swagger
先贴官方地址,我的做法差不多 https://github.com/goharbor/harbor/blob/master/docs/configure_swagger.md 1.下载对应资源 wge ...
- 在Office 365 的如何给管理员赋予查看所有人邮箱的权限的Powershell
连接至Office365 的Powershell Get-MsolUser -UserPrincipalName admin@***.partner.onmschina.cn //Get-MsolUs ...
- POJ 1417 并查集 dp
After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ...