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 ...
随机推荐
- Android笔记之文本随滑块移动的SeekBar
效果图 FloatingTextSeekBar.java package com.bu_ish.blog; import android.content.Context; import android ...
- smod包含具体的增强(具体实施对象) / CMOD 包含一组smod编写的增强
从标题来看,CMOD 是树木,smod 是树枝. 1.1 SMOD包含具体的增强,而CMOD是包含一组SMOD编写的增强. 1.2 User exits (Function module exits) ...
- LVS项目介绍
LVS项目介绍 章文嵩 (wensong@linux-vs.org) 转自LVS官方参考资料 2002 年 3 月 本文介绍了Linux服务器集群系统--LVS(Linux Virtual Serve ...
- Hihocoder #1095 : HIHO Drinking Game (微软苏州校招笔试)( *【二分搜索最优解】)
#1095 : HIHO Drinking Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playin ...
- laravel基础课程---1、laravel安装及基础介绍(laravel如何安装)
laravel基础课程---1.laravel安装及基础介绍(laravel如何安装) 一.总结 一句话总结: [修改composer镜像地址].[明确laravel的安装要求].[安装指定版本的la ...
- js获取dom对象style样式的值
js获取到的dom对象的style通常是没有值得,因为我们都写在外部文件中,从慕课网上见到讲师封装的一个方法,挺不错.特此记录下来. function getStyle(obj,attr){ if(o ...
- Asterisk 拨号方案中截取字符串
在dialplan中要截取字符串可用如下几种方式: 1.转到agi中由php进行处理,这种方法比较简单,在这里不再缀述 2.在dialplan中利用内置的方法进行截取 如 [test] exten = ...
- 51nod-1065:最小正子段和(STL)
N个整数组成的序列a11,a22,a33,…,ann,从中选出一个子序列(aii,ai+1i+1,…ajj),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的. 例如:4,-1 ...
- Rsyslog 日志相关内容
[root@server vusers_home]# rpm -ql rsyslog|more ###.so结尾为模块,模块有分im为输入模块,om 为输出模块/etc/logrotate ...
- BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP
BZOJ_3887_[Usaco2015 Jan]Grass Cownoisseur_强连通分量+拓扑排序+DP Description In an effort to better manage t ...