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 ...
随机推荐
- 优步UBER司机全国各地奖励政策汇总 (3月28日-4月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 北京Uber优步司机奖励政策(2月22日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- php post
post form function post($remote_server,$data,$second=60){ $ch = curl_init();if(is_string($data)){ $t ...
- ASP.NET数据库连接
启动Visual Studio,新建一个web工程 点开工程目录下web.config文件, 找到节点,新增数据库配置 aspx界面新建一个button和一个文本框用于测试数据库连接, 其中butto ...
- C# 简单工厂
如下: public static IList<T> Create<T>(Type type) { if (type == typeof(List<T>)) { r ...
- mysql 各种存储引擎的特点
- LeetCode - 326, 342, 231 Power of Three, Four, and Two
1. 问题 231. Power of Two: 判断一个整数是否是2的n次方,其中n是非负整数 342. Power of Four: 判断一个整数是否是4的n次方,其中n是非负整数 326. Po ...
- eos开发指南
十分钟教你开发EOS智能合约 在CSDN.柏链道捷(PDJ Education).HelloEOS.中关村区块链产业联盟主办的「EOS入门及最新技术解读」专场沙龙上,柏链道捷(PDJ Educatio ...
- HADOOP docker(一):安装hadoop实验集群(略操蛋)
一.环境准备 1.1.机器规划 主机名 别名 IP 角色 9321a27a2b91 hadoop1 172.17.0.10 NN1 ZK RM 7c3a3c9cd595 hadoo ...
- js如何处理字符串中带有↵字符
js或vue中如何处理字符串中带有↵字符 split('\n') 使用split('\n')将字符串分割成数组就行 如果我们在vue中,只需要在页面中绑定变量时操作split('\n')就可以了: & ...