【ZOJ 1221】Risk
2016-02-14 00:53
471 查看
题
题意
给你20个城市的相邻关系,求给定任意两个城市的最短距离分析
求任意两个城市最短距离,就是用floyd算法,我脑残忘记了k是写在最外层的。代码
#include<stdio.h> #include<algorithm> #define N 22 using namespace std; int n,x,a,b,test,d ,from,to; void read() { for(int j=1; j<=x; j++) { scanf("%d",&b); d[a][b]=d[b][a]=1; } } int main() { while(~scanf("%d",&x)) { test++; for(int i=1; i<=20; i++)for(int j=1; j<=20; j++)d[i][j]=50; a=1;read(); for(a=2; a<20; a++) { scanf("%d",&x); read(); } for(int k=1; k<=n; k++)//k写在外面 for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]); scanf("%d",&n); printf("Test Set #%d\n",test); for(int i=1; i<=n; i++) { scanf("%d%d",&from,&to); printf("%d to %d: %d\n",from,to,d[from][to]); } printf("\n"); } return 0; }
相关文章推荐
- MOOC Machine Learning 作业交流帖4
- 数组中添加数据后并排序显示出来
- 最短路算法floyd
- js验证输入,自定义错误提示
- [回文自动机]bzoj2342: [Shoi2011]双倍回文
- 集群监控_Ganglia使用入门
- 机器学习实践-Ch02 kNN分类算法
- MOOC Machine Learning 作业交流帖3
- Amazon coding 题解答
- QQ中对话框图片的拉伸问题
- 1038. Recover the Smallest Number (30)
- NodeJS 断言的使用
- html背景图片定位方法
- leetcode 83. Remove Duplicates from Sorted List
- Bestcoder Round 72# div2
- MOOC Machine Learning 作业交流帖2
- HDU5627--Clarke and MST (bfs+位运算)
- 有限状态机
- 数据结构热身
- 编写一个程序,把C语言的声明翻译成通俗语言