본문 바로가기

problem solving/Problem Solving

Risk

http://acm.pku.edu.cn/JudgeOnline/problem?id=1603

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 first sample input.

Source

South Central USA 1997


Solving

20개의 노드가 존재하는 그래프 문제이다. 어느 한 노드에서 다른 노드로 가는데 최소한 몇 번을 움직여야 하는지 묻고있다.
하나의 그래프에 대해 여러번에 걸쳐 시작노드와 종료노드를 바꿔가며 물어보기 때문에 전쌍최단경로 알고리즘을 이용하여 풀면 되겠다.


'problem solving > Problem Solving' 카테고리의 다른 글

Subsequence  (0) 2008.10.02
Center of symmetry  (0) 2008.10.02
All in All  (0) 2008.10.02
Tug of War  (0) 2008.10.02
Ones  (0) 2008.10.02