hdu 2722 Here We Go(relians) Again (最短路径)
Here We Go(relians) Again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 685 Accepted Submission(s): 335
Fortunately for the Gorelian Minister of Traffic (that would be you), all Gorelian cities are laid out as a rectangular grid of blocks, where each block is a square measuring 2520 rels per side (a rel is the Gorelian Official Unit of Distance). The speed limit between two adjacent intersections is always constant, and may range from 1 to 9 rels per blip (a blip, of course, being the Gorelian Official Unit of Time). Since Gorelians have outlawed decimal numbers as unholy (hey, if you're the dominant force in the known universe, you can outlaw whatever you want), speed limits are always integer values. This explains why Gorelian blocks are precisely 2520 rels in length: 2520 is the least common multiple of the integers 1 through 9. Thus, the time required to travel between two adjacent intersections is always an integer number of blips.
In all Gorelian cities, Government Housing is always at the northwest corner of the city, while the Government Building is always at the southeast corner. Streets between intersections might be one-way or two-way, or possibly even closed for repair (all this tinkering with traffic patterns causes a lot of accidents). Your job, given the details of speed limits, street directions, and street closures for a Gorelian city, is to determine the fastest route from Government Housing to the Government Building. (It is possible, due to street directions and closures, that no route exists, in which case a Gorelian Official Temporary Holiday is declared, and the Gorelian Officials take the day off.)
The picture above shows a Gorelian City marked with speed limits, one way streets, and one closed street. It is assumed that streets are always traveled at the exact posted speed limit, and that turning a corner takes zero time. Under these conditions, you should be able to determine that the fastest route from Government Housing to the Government Building in this city is 1715 blips. And if the next day, the only change is that the closed road is opened to two way traffic at 9 rels per blip, the fastest route becomes 1295 blips. On the other hand, suppose the three one-way streets are switched from southbound to northbound (with the closed road remaining closed). In that case, no route would be possible and the day would be declared a holiday.
构图有点小麻烦,粗心WA了好几次 = =,其实是简单题。
//0MS 260K 2045 B C++
#include<stdio.h>
#include<string.h>
#define N 505
#define inf 0x3fffffff
struct node{
int v,d,next;
}edge[*N];
int Head[N];
int vis[N];
int d[N];
int n,edgenum;
void addedge(int u,int v,int d)
{
edge[edgenum].v=v;
edge[edgenum].d=d;
edge[edgenum].next=Head[u];
Head[u]=edgenum++;
}
void spfa(int u)
{
int Q[N],head=,tail=;
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
d[i]=inf;
d[u]=;
vis[u]=;
Q[head]=u;
while(head!=tail){
u=Q[head++];
vis[u]=;
for(int i=Head[u];i!=-;i=edge[i].next){
int v=edge[i].v;
int w=edge[i].d;
if(d[v]>d[u]+w){
d[v]=d[u]+w;
if(!vis[v]){
Q[tail++]=v;
vis[v]=;
tail%=n;
}
}
}
head%=n;
}
}
int main(void)
{
int r,c,u,v,w;
char op;
while(scanf("%d%d",&r,&c)!=EOF && (r+c))
{
memset(Head,-,sizeof(Head));
edgenum=;
for(int i=;i<*r+;i++){
int flag=i%;
for(int j=;j<c+flag;j++){
scanf("%d %c",&w,&op);
if(w==) w=inf;
else w=/w;
u=i/*(c+)+j;
if(i%) v=(i/+)*(c+)+j;
else v=u+;
//printf("**%d %c %d %d\n",w,op,u,v);
if(i%){
if(op=='*'){addedge(u,v,w);addedge(v,u,w);}
else if(op=='v') addedge(u,v,w);
else addedge(v,u,w);
}else{
if(op=='*'){addedge(u,v,w);addedge(v,u,w);}
else if(op=='>')addedge(u,v,w);
else addedge(v,u,w);
}
}
}
n=(r+)*(c+);
spfa();
if(d[n-]==inf) puts("Holiday");
else printf("%d blips\n",d[n-]);
}
return ;
}
hdu 2722 Here We Go(relians) Again (最短路径)的更多相关文章
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...
- HDU 2722 Here We Go(relians) Again (spfa)
Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/ ...
- HDU 2722 Here We Go(relians) Again
最短路,建图太麻烦,略过…… #include <cstdio> #include <cstring> #include <queue> const int INF ...
- HDU 2722 Here We Go(relians) Again (最短路)
题目链接 Problem Description The Gorelians are a warlike race that travel the universe conquering new wo ...
- hdu 2544 最短路(两点间最短路径)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2544 方法一:dijkstra算法,求两点之间最短路径. /*********************** ...
- hdu 1142 A Walk Through the Forest (最短路径)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- 【HDOJ】2722 Here We Go(relians) Again
根据矩阵建图,然后求最短路径. #include <cstdio> #include <cstring> #include <cstdlib> #define L ...
- HDU - 2066 一个人的旅行(最短路径)(模板)
d.每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有S个(草儿家到这个城市的距离设为0),草儿想去的地方有D个: 求D个城市中距离草儿家最近的距离. s.进行1次单源最短路,找出 ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
随机推荐
- Fliptil_KEY
Fliptil(fliptile.pas/c/cpp) [问题描述] 约翰知道,那些高智力又快乐的奶牛产奶量特别高.所以他做了一个翻瓦片的益智游戏来娱乐奶牛. 在一个M×N的骨架上,每一个格子里都有一 ...
- 北京Uber优步司机奖励政策(3月30日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 深圳Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 成都Uber优步司机奖励政策(2月28日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Android Preference 设置偏好全攻略
Android 设置是每个App必不可小的东西,看似很简单,但是初学不熟悉的很花时间去研究,特别样式兼容方面,以及有自定义设置的需求,下面是对用法做一个总结 Preference结构 界面结构看下图 ...
- InnoDB锁冲突案例演示(续)
Preface I've demontstrated several InnoDB locking cases in my previous blog.I'm gonna do the ...
- 感觉总结了一切python常见知识点,可直接运行版本
#encoding=utf-8#http://python.jobbole.com/85231/#作用域a=1def A(a): a=2 print 'A:',a def B(): print 'B: ...
- Java 输出对象为字符串 工具类
public static String reflectionToString(Object o){ if(o == null) return StringUtils.EMPTY; StringBui ...
- Struts2(八.添加用户多张照片实现文件上传功能)
1.modify.jsp 在modify.jsp修改用户信息页面实现文件上传,添加用户照片的功能 如果是文件上传,method必须是post,必须指定enctype <form method=& ...
- leetcode-汉明距离
汉明距离 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目. 给出两个整数 x 和 y,计算它们之间的汉明距离. 注意: 0 ≤ x, y < 231. 示例: 输入: x = ...