POJ_1847_Tram
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 11159 | Accepted: 4089 |
Description
When a driver has do drive from intersection A to the intersection B he/she tries to choose the route that will minimize the number of times he/she will have to change the switches manually.
Write a program that will calculate the minimal number of switch changes necessary to travel from intersection A to intersection B.
Input
Each of the following N lines contain a sequence of integers separated by a single blank character. First number in the i-th line, Ki (0 <= Ki <= N-1), represents the number of rails going out of the i-th intersection. Next Ki numbers represents the intersections directly connected to the i-th intersection.Switch in the i-th intersection is initially pointing in the direction of the first intersection listed.
Output
Sample Input
- 3 2 1
- 2 2 3
- 2 3 1
- 2 1 2
Sample Output
- 0
Source
- #include<iostream>
- #include<cstdio>
- using namespace std;
- #define N 1000000
- int map[][];
- int main()
- {
- int n,sta,end,m,a;
- int i,j;
- scanf("%d%d%d",&n,&sta,&end);
- for(i=; i<=n; i++)
- for(j=; j<=n; j++)
- map[i][j]=N;
- for(i=; i<=n; i++)
- {
- scanf("%d",&m);
- for(j=; j<=m; j++)
- {
- scanf("%d",&a);
- if(j==)
- map[i][a]=;
- else
- map[i][a]=;
- }
- }
- int k;
- for(k=; k<=n; k++) //floyd算法
- for(i=; i<=n; i++)
- for(j=; j<=n; j++)
- if(map[i][k]+map[k][j]<map[i][j])
- map[i][j]=map[i][k]+map[k][j];
- if(map[sta][end]<N)
- cout<<map[sta][end]<<endl;
- else
- cout<<-<<endl;
- return ;
- }
POJ_1847_Tram的更多相关文章
随机推荐
- 中文分词实践(基于R语言)
背景:分析用户在世界杯期间讨论最多的话题. 思路:把用户关于世界杯的帖子拉下来.然后做中文分词+词频统计,最后将统计结果简单做个标签云.效果例如以下: 兴许:中文分词是中文信息处理的基础.分词之后.事 ...
- android中怎么将桌面较长的图标名称显示完整
找到相应的 res 资源, 改动其 styles.xml <style name="WorkspaceIcon.Portrait"> <item ...
- Cg入门20:Fragment shader - 片段级模型动态变色(实现汽车动态换漆)
Unity 一个面片的最大顶点数为65524,所以大于这个数,请拆分成多个面片 1.获取汽车x轴的最大值和最小值[-2.5,2.5]+R watermark/2/text/aHR0cDovL2Jsb2 ...
- JavaScript你所不知道的困惑(1)
困惑一: 先看一个样例: function test(){ message = "hi"; } test(); alert(message); 会输出字符串"hi&quo ...
- cp和scp
1 两个命令的格式一样 cp src dst scp src dst 将src文件拷贝到dst目的地.cp是本机拷贝,即从本机的一个地方拷贝到另外一个地方. 而scp是拷贝到远程及其还是从远程机器拷贝 ...
- javax.servlet.http.Part 文件上传
编辑jsp页面: <html> <head> <base href="<%=basePath%>"> <title>My ...
- Java 相关计数问题及其实现
数(三声)数(四声)问题自然使用非负整数: 0. 一个类作为一个计数器 java 语法 -- final class Counter { private static long counter; pr ...
- 使用nginx搭建媒体点播服务器
使用nginx搭建媒体点播服务器 最新由于兴趣,对ubuntu和安卓上的视频点播直播等应用比较感兴趣,所以在vmware的虚拟机里面搭建了一个视频点播网站,参考了fengzhanhai的文章Nginx ...
- source命令用法(转载)
转自:http://zhidao.baidu.com/link?url=mNfsPHSjTEm7llgyMYx0UVNwkJmD_cxLeHtZnHcM6Ms8LDXofVHka_EzHi6GltbR ...
- bzoj 1045: [HAOI2008] 糖果传递【瞎搞】
感觉我的智商可能不够写题解,就直接截了hzwer的blog 地址http://hzwer.com/2656.html #include<iostream> #include<cstd ...