UVA 567 - Risk(最短路)

zoj1221 这道题目之前听老师讲感觉晕晕乎乎的 昨天看懂了弗洛伊德算法之后 发现这道题原来是这么基础。。 但是第一次只提交了2次就A了 还只是因为EOF的设置问题 开心!! #include using namespace std; int map[21][21]; void test(); int min(int a, int b); int main() { int n,i,a,b 阅读详情

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 <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=111;
const int maxm=111111;
const int INF=0x3f;
int vis[22][22];

void floyd()
{
    for (int k=1;k<=20;k++)
    {
        for (int i=1;i<=20;i++)
        {
            for (int j=1;j<=20;j++)
            {
                vis[i][j]=min(vis[i][j],vis[i][k]+vis[k][j]);
            }
        }
    }
}

int main()
{
    int cas=0,n,u,v;
    while(~scanf("%d",&n))
    {
        memset(vis,INF,sizeof(vis));
        for(int i=1;i<=20;i++)
            vis[i][i]=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&v);
            vis[1][v]=vis[v][1]=1;
        }
        for(int i=2;i<20;i++)
        {
            scanf("%d",&n);
            for(int j=0;j<n;j++)
            {
                scanf("%d",&v);
                vis[i][v]=vis[v][i]=1;
            }
        }
        floyd();
        printf("Test Set #%d\n",++cas);
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&u,&v);
            printf("%d to %d: %d\n",u,v,vis[u][v]);
        }
        printf("\n");
    }
    return 0;
}


【WRF-Urban运行】WRF-SLUCM耦合建模参数设置及模拟运行 WRF-SLUCM耦合建模参数设置及模拟运行 阅读详情

相关推荐

基于STM32平衡小车设计

随着智能硬件的发展,基于STM32的两轮智能平衡车作为一种新型的智能移动工具,具备较高的应用价值。本文旨在设计并实现一款基于STM32微控制器的智能平衡车系统,提升其稳定性和操控性,探索如何通过传感器数据和控制算法实现精确平衡控制。 本设计基于STM32微控制器,选择了STM32F103系列作为核心控制器,具有足够的处理能力和丰富的外设接口。系统通过MPU6050传感器获取三轴加速度和三轴陀螺仪数据,实现实时姿态检测。电机驱动部分采用合适的驱动模块,能够控制两个直流电机,并支持PWM调速。设计中还包括OL

m0_74026776的博客 2730

ZOJ-1221-Risk

题目链接:https://vjudge.net/problem/ZOJ-1221 Risk 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

Mongo_girl 311

Linux系统遭遇挖矿病毒深度排查与根治指南

本文提供了一份详尽的Linux服务器挖矿病毒排查与根治指南。当CPU异常满载但常规top命令无法定位进程时,需警惕病毒通过ld.so.preload文件隐藏。文章逐步指导如何清除恶意文件、进程、定时任务,并重点应对pamdicks等顽固变种,最后给出深度排查与系统加固方案,确保服务器安全。

weixin_29207533的博客 453

ZOJ-1221

水,全源无权最短路,Floyd一次完事了 #include #include #include int main() { int cs = 0, count, d[21][21]; while (scanf("%d", &count) != EOF) { int k, i, j, t; for (i = 1; i <= 20; i++) for (j = 1; j <= 2

xhldtc的专栏 827

拆解全球18大“支付清算”体系:CLS、中国、美国、欧洲、日本、mBridge...

拆解全球18大“支付清算”体系:CLS、中国、美国、欧洲、日本、mBridge...

银行信息系统应用架构详解 884

第八届传智杯WPS智能办公能力挑战赛练习题库

本文是关于WPS Office软件操作知识的选择题汇总,内容涵盖WPS文字、表格和演示三大组件的常用功能。主要包括:云文档协同编辑、文本框插入、幻灯片打印设置、数据排序与筛选、函数应用(如SUMIF、COUNT)、动画效果设置、格式刷使用、页眉页脚设置、单元格引用类型等基础操作要点。同时涉及计算机基础概念如二进制、ROM存储器等。题目以单选和多选形式呈现,附带详细答案解析,全面检验用户对WPS办公软件的功能掌握程度和实际操作能力,适用于办公软件技能培训和水平测试。

qq_73044452的博客 1432

zoj 1221

用dijkstra算法 没有测试是否满足所有的,但是给出的都对上了。 import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Queue; import java.util.Scanner; import java.util.concurrent.PriorityBlockingQueue; p

安逸风声 486

基于STC8G1K08A单片机的PCA捕获外部信号(100~1000HZ)程序实现

基于STC8G1K08A单片机的PCA捕获外部信号(100~1000HZ)程序实现

weixin_74013772的博客 255

zoj 1221Risk—dijkstra算法和Floyd算法

1.dijkstra算法实现 #include #include #include #include int edge[21][21]; int visit[21]; int dis[21]; #define INF 0x3f3f3f3f int dijkstra(int s,int e){ int i,j,k; memset(visit,0,sizeof(visit)); for(i=1

…… 447

大数据领域数据产品的团队激励与绩效管理

在大数据领域,数据产品的成功离不开高效协作的团队。团队激励与绩效管理的目的在于激发团队成员的工作热情和创造力,提高工作效率和质量,确保数据产品能够按时、高质量地交付。本文章的范围涵盖了大数据领域数据产品团队激励与绩效管理的各个方面,包括激励机制的设计、绩效评估的方法、团队沟通与协作等。本文将按照以下结构进行阐述:首先介绍核心概念与联系,明确相关概念的定义和相互关系;接着讲解核心算法原理和具体操作步骤,为团队激励与绩效管理提供理论支持和实践指导;然后分析数学模型和公式,帮助读者深入理解绩效评估的原理;

Java大师兄的博客 1018

02 HCM CPI SF集成-组织集成(一)

将员工主数据和组织数据从SAP Successfactors Employee CentraI复制到SAPERP或SAP S/4HANA,SAP SF CPI HCM集成

SAP CPI 129

uva 567 Risk(最短路Folyd)

题目链接:567 - Risk 题目大意:固定有20个点,然后输入19行的数据,没一行先输入一个n,表示该行还有n个数,然后输入n个数,表示每个数与该行的序号数相同的点有连接,并且权值为1, 在数入m,表示有m次询问,每个询问包含两个数值a,b,输出ab间的最短路径。 解题思路:裸的Floyd算法,算法参见《算法竞赛入门经典》P206。 #include #in

不慌不忙、不急不躁 1452

使用 MATLAB/Simulink + Reinforcement Learning Toolbox 构建一个基于强化学习的永磁同步电机(PMSM)自适应控制仿真系统

随着人工智能(AI)技术的快速发展,强化学习(Reinforcement Learning, RL)在控制系统中的应用日益广泛。在电机控制领域,传统的PID控制虽然成熟稳定,但在面对非线性、时变、不确定负载等复杂工况时,其控制性能可能受限。而强化学习通过与环境的交互学习,能够实现在线自适应控制策略优化,显著提升系统的鲁棒性与响应速度。本教程将带你使用构建一个基于强化学习的永磁同步电机(PMSM)自适应控制仿真系统,实现从控制策略设计、环境建模、训练到仿真的全过程。当前转速(ω)

amy_mhd的博客 407

UVa567_Risk(最短路)(小白书图论专题)

解题报告 题目传送门 题意: 有20个城市,仅仅能征服相邻的城市,问要征服目的城市,最少须要征服多少城市(包含目的城市) 思路: 多源最短路,直接floyd,点才20个。 #include &lt;iostream&gt; #include &lt;cstring&gt; #include &lt;cstdio&gt; #define inf 0x3f3f3f3f usin...

weixin_34044273的博客 123

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

acm专题学习之最短路(二)Floyd算法+UVa567_Risk

题目:有20个城市,只能征服相邻的城市,让求任意给定两个城市的最短路 Floyd算法:(多源最短路径)用于求任意两个点之间的最短路径 算法的思路:枚举每两个点,枚举中间必须经过中转点,取最小值(动态规划算法dis(i,j) =min(dis(i,k) + dis(k,j),dis(i,j))) 与Dijkstra区别:1Dijkstra是单源点,Floyd是多源点 2Dijkstra不存...

qq_40306845的博客 250

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

UVa 567 Risk (Floyd+任意两点最短路)

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int INF=100000000; int d[25][25]; void Floyd( ) { for(int k=1;

Slow_Wakler的专栏 538

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

UVa 567 Risk 解答

题目描述:http://uva.onlinejudge.org/external/5/567.html 典型的最短路径问题,采用dijkstra算法实现如下: /* * 567.cc * * Created on: Jan 8, 2013 * Author: root */ #include #include const int INF = 100;

guixunlong的专栏 587

UVa 567 Risk

题目要求计算给定无向图中任意两节点之间的最短路径(边数)。图包含20个节点,输入描述每个节点与更高编号节点的连接关系,然后进行多组查询。使用Floyd-Warshall算法预处理所有点对的最短路径,查询时直接输出结果。代码实现中初始化邻接矩阵,通过三重循环更新最短路径,最后按格式输出查询结果。算法复杂度为O(20^3),可以高效处理题目要求。

寂静山林 191

A - Risk UVA - 567(Floyd)

1.题目 A - Risk UVA - 567 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 playe...

weixin_45674799的博客 203

UVA567 Risk【最短路径+Floyd算法】

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 countr

海岛Blog 515

【ICPC-302】uva 567 Risk

点击打开链接uva 567 1思路:最短路+floyd 2分析:题目给定的点的个数为20,那么根据f'loyd的时间复杂度不会超时,那么直接利用floyd即可。 3注意输出的格式问题 代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring...

藏经阁 | 玄苦 1539

UVA 567 Risk

题目链接 UVA 567 题意: 一个游戏,有 20 个城市,编号为 1 - 20 ,有一些道路,连接两个城市,求从一个城市到另一个城市 要经过的最小道路个数。 分析: Floyd 算法,求任意两点之间的最短路。 代码: #include #include #include #include #include #include using na

Houheshuai的专栏 522

UVA 567 Risk【floyd】

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=508 题意:20个点的随意最短路。floyd 代码: #include <stdio.h> #include &lt...

aodiyi6351的博客 144

UVA - 567 Risk(Floyd)

UVA - 567 Risk(Floyd) 题目链接 题目大意:有20个城市,输入给19行,每行先给有几个数,然后接着给出这几个数,代表的是后面的城市编号和行编号(城市编号)有一条边,每条边的权值为1.接着m个查询任意两个城市之间的最短距离。 解题思路:求任意两个顶点之间的距离,用floyd。 代码: #include const int maxn = 21; const i

788

UVA 567 求最短路问题

Risk 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, a...

dizhuang3784的博客 192

UVA - 567 Risk(Floyd)

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

王蒟蒻 224
上一篇: 几何模板
下一篇: HDU 1754 - I Hate It(线段树)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值