Description

Risk is a board game in which several opposing players attempt to conquer the world. The gameboard consists of a world map broken up into hypothetical countries. During a player's turn, armies stationed in one country are only allowed to attack only countries with which they share a common border. Upon conquest of that country, the armies may move into the newly conquered country.

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

Input to your program will consist of a series of country configuration test sets. Each test set will consist of a board description on lines 1 through 19. The representation avoids listing every national boundary twice by only listing the fact that country I borders country J when I < J. Thus, the Ith line, where I is less than 20, contains an integer X indicating how many "higher-numbered" countries share borders with country I, then X distinct integers J greater than I and not exceeding 20, each describing a boundary between countries I and J. Line 20 of the test set contains a single integer (1 <= N <= 100) indicating the number of country pairs that follow. The next N lines each contain exactly two integers (1 <= A,B <= 20; A!=B) indicating the starting and ending countries for a possible conquest.

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

For each input set, your program should print the following message "Test Set #T" where T is the number of the test set starting with 1. The next NT lines each will contain the result for the corresponding test in the test set - that is, the minimum number of countries to conquer. The test result line should contain the start country code A the string " to " the destination country code B ; the string ": " and a single integer indicating the minimum number of moves required to traverse from country A to country B in the test set. Following all result lines of each input set, your program should print a single blank line.

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的更多相关文章

  1. ZOJ1221 && UVA567:Risk(Floyd)

    Risk is a board game in which several opposing players attempt to conquer the world. The gameboard c ...

  2. PHP Datatype Conversion Safety Risk、Floating Point Precision、Operator Security Risk、Safety Coding Principle

    catalog . 引言 . PHP operator introduction . 算术运算符 . 赋值运算符 . 位运算符 . 执行运算符 . 递增/递减运算符 . 数组运算符 . 类型运算符 . ...

  3. Linux fork()、exec() Hook Risk、Design-Principle In Multi-Threadeed Program

    目录 . Linux exec指令执行监控Hook方案 . 在"Multi-Threadeed Program"环境中调用fork存在的风险 . Fork When Multi-T ...

  4. UVa12264 Risk(最大流)

    题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. Threat Risk Modeling Learning

    相关学习资料 http://msdn.microsoft.com/en-us/library/aa302419(d=printer).aspx http://msdn.microsoft.com/li ...

  6. Stakeholder Risk Management

    In this article we'll address the people swirling around your project: stakeholders. You'll find som ...

  7. 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 ...

  8. zoj 1221 Risk Flory

    博客开了快半年了- -学习编程也快1年半了,觉得空空的不太好看,刚好最近开始练习ACM了,就来做一个简单的ACM学习笔记吧,纪念的第一题zol 1221 Risk 风险游戏(个人觉得是这样翻- -翻译 ...

  9. UVa 567: Risk

    这是一道很简单的图论题,只要使用宽度优先搜索(BFS)标记节点间距离即可. 我的解题代码如下: #include <iostream> #include <cstdio> #i ...

随机推荐

  1. ETF到底是什么?

    ETF(交易所交易基金)是一种证券产品,它可以跟踪一些相关的资产,不论是股票.债券.商品,还是数字货币. ETF基金会负责跟踪指定的资产.然后放出部分股份,这些股份代表着对资产的拥有权. 交易ETF股 ...

  2. 前端面试常考知识点---CSS

    前端面试常考知识点---js 1.CSS3的新特性有哪些 点我查看 CSS3选择器 . CSS3边框与圆角 CSS3圆角border-radius:属性值由两个参数值构成: value1 / valu ...

  3. [haoi2015]T1

    题意:给定你一颗树,要求你在这棵树中确定K个黑点和N-K个白点,使黑点间与白点间两两距离之和最大,输出最大值.n<=2000 对于这道题,我想了好几个思路,包括点分治,贪心,动规,网络流等等,实 ...

  4. bzoj4670: 佛罗里达

    这题直接随机化+贪心就可以爆踩过去,我加了个退火增加容错率而已....其实你随机的次数够多根本不需要... 然后来自肉丝哥哥的正经做法: 先钦定D(A)>D(B),那么可以枚举D(A),然后再去 ...

  5. iOS:UITextField中文输入法输入时对字符长度的限制

      如题的问题,又是个让我抓狂了大半天的问题,还是做个记录,有与类似问题的同学可参考,但不一定对.具体问题还需具体分析.我遇到的需求是这样的:有一个输入框,输入框内输入文字,文字字数限制在20字.   ...

  6. html5--4-2 video元素的属性

    html5--4-2 video元素的属性 学习要点 掌握video元素的基本用法 直到现在,在网页中的大多数视频是通过插件(比如 Flash)来显示的.然而,并非所有浏览器都拥有同样的插件.HTML ...

  7. 自适应布局all样式

    /*css document*/@charset "utf-8"*{-webkit-tap-highlight-color:rgba(0,0,0,0); padding:0; ma ...

  8. BeginPaint/EndPaint(CPaintDC)与GetDC(CClientDC)的区别

    在OnPaint函数中,用CClientDC dc(this)代替CPaintDC(this)后,界面不断闪烁. 说明:CClientDC是对GetDC的使用封装, CPaintDC是对BeginPa ...

  9. python 基础之第十二天(re正则,socket模块)

    In [14]: 'hello-wold.tar.gz'.split('.') Out[14]: ['hello-wold', 'tar', 'gz'] In [15]: import re In [ ...

  10. [BZOJ 1475] 方格取数

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1475 [算法] 首先将方格黑白染色 , 也就是说 , 如果(i + j)为奇数 , ...