ZOJ1221 Risk
Description
During the course of play, a player often engages in a sequence of conquests with the goal of transferring a large mass of armies from some starting country to a destination country. Typically, one chooses the intervening countries so as to minimize the total number of countries that need to be conquered. Given a description of the gameboard with 20 countries each with between 1 and 19 connections to other countries, your task is to write a function that takes a starting country and a destination country and computes the minimum number of countries that must be conquered to reach the destination. You do not need to output the sequence of countries, just the number of countries to be conquered including the destination. For example, if starting and destination countries are neighbors, then your program should return one.
The following connection diagram illustrates the sample input.

Input
There can be multiple test sets in the input; your program should continue reading and processing until reaching the end of file. There will be at least one path between any two given countries in every country configuration.
Output
Sample Input
1 3
2 3 4
3 4 5 6
1 6
1 7
2 12 13
1 8
2 9 10
1 11
1 11
2 12 17
1 14
2 14 15
2 15 16
1 16
1 19
2 18 19
1 20
1 20
5
1 20
2 9
19 5
18 19
16 20
Sample Output
Test Set #1
1 to 20: 7
2 to 9: 5
19 to 5: 6
18 to 19: 2
16 to 20: 2
裸的floyd模板,交代码:
#include <bits/stdc++.h>
int low[][],f[][],i,j,x,n,a,b,k;
int main()
{ int sum=;
while(scanf("%d",&x)!=EOF)
{
sum++;
for(i=;i<=;i++)
for(j=;j<=;j++)
low[i][j]=;
for(k=;k<=x;k++)
{
scanf("%d",&j);
low[][j]=low[j][]=;
}
for(i=;i<=;i++)
{
scanf("%d",&x);
for(k=;k<=x;k++)
{
scanf("%d",&j);
low[i][j]=low[j][i]=;
}
}
for(k=;k<=;k++)
for(i=;i<=;i++)
for(j=;j<=;j++)
if(low[i][j]>low[i][k]+low[k][j])
low[i][j]=low[i][k]+low[k][j];
scanf("%d",&n);
printf("Test Set #%d\n",sum);
for(i=;i<=n;i++)
{
scanf("%d%d",&a,&b);
printf("%d to %d: %d\n",a,b,low[a][b]);
}
printf("\n");
}
}
ZOJ1221 Risk的更多相关文章
- ZOJ1221 && UVA567:Risk(Floyd)
Risk is a board game in which several opposing players attempt to conquer the world. The gameboard c ...
- PHP Datatype Conversion Safety Risk、Floating Point Precision、Operator Security Risk、Safety Coding Principle
catalog . 引言 . PHP operator introduction . 算术运算符 . 赋值运算符 . 位运算符 . 执行运算符 . 递增/递减运算符 . 数组运算符 . 类型运算符 . ...
- Linux fork()、exec() Hook Risk、Design-Principle In Multi-Threadeed Program
目录 . Linux exec指令执行监控Hook方案 . 在"Multi-Threadeed Program"环境中调用fork存在的风险 . Fork When Multi-T ...
- UVa12264 Risk(最大流)
题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- Threat Risk Modeling Learning
相关学习资料 http://msdn.microsoft.com/en-us/library/aa302419(d=printer).aspx http://msdn.microsoft.com/li ...
- Stakeholder Risk Management
In this article we'll address the people swirling around your project: stakeholders. You'll find som ...
- 10 Golden Rules of Project Risk Management
The benefits of risk management in projects are huge. You can gain a lot of money if you deal with u ...
- zoj 1221 Risk Flory
博客开了快半年了- -学习编程也快1年半了,觉得空空的不太好看,刚好最近开始练习ACM了,就来做一个简单的ACM学习笔记吧,纪念的第一题zol 1221 Risk 风险游戏(个人觉得是这样翻- -翻译 ...
- UVa 567: Risk
这是一道很简单的图论题,只要使用宽度优先搜索(BFS)标记节点间距离即可. 我的解题代码如下: #include <iostream> #include <cstdio> #i ...
随机推荐
- 看不懂JDK8的流操作?5分钟带你入门(转)
在JDK1.8里有两个非常高级的新操作,它们分别是:Lambda 表达式和 Stream 流. Lambda表达式 让我们先说说 Lambda 表达式吧,这个表达式最大的作用就是简化语法,让代码更加易 ...
- Ubuntu搜狗输入法候选词乱码
打开Fcitx Configuration,进入Addon标签 选中Simplified Chinese To Traditional Chinese Convert Simplified ...
- 分布式版本控制系统—git命令
一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...
- httpd 隐藏文件
问题情况, 因磁盘空间问题,使用rsync将 php工作目录下文件copy到新盘中后,出现 php服务很多目录访问返回 404,路径找不到,其实文件都存在,而且路径都是对的 解决思路. 根目录下 有个 ...
- object_test.py
#方法,属性,私有化加双下划线 ''' __a 从外部无法访问,但是类的内部可以访问.实际上还是能在类外访问这些私有方法,尽管不应该这么做:s._A__a 如果不需要使用这种方法但是又不行让其他对象不 ...
- BZOJ_3786_星系探索_splay维护出栈入栈序
BZOJ_3786_星系探索_splay维护出栈入栈序 Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为 ...
- BZOJ_3545_[ONTAK2010]Peaks_主席树+倍增+kruscal重构树+dfs序
BZOJ_3545_[ONTAK2010]Peaks_主席树+倍增+kruscal重构树 Description 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道 ...
- JavaScript 日期处理类库 moment
可以自定义自己需要的时间格式,中文文档如下: http://momentjs.cn/ http://momentjs.cn/docs/
- C语言之数组与指针的易混淆知识点
一.指针与数组 指针:指针本身也是一个变量,它的内容是指向的内容的地址.指针同样有类型的区分,char 的指针只能指向char型数据,int 指针指向int型数据.但是指针所占内存单元的大小(即其内容 ...
- VS中文档大纲视图的作用
一.在vs的菜单栏中点击视图==========>其他窗口===========>文档大纲 二.文档大纲的作用是可以查看当前Form窗体的结构,如下图 三.若果感觉控件的类型太长,可以在文 ...