poj - A funny game-2599
2017-08-13 13:52
375 查看
Description
There are several airports in one country, and there are flights between some of them. One can fly from any airport to any other, probably with some changes. For any pair of airports there exists only one sequence of flights that connects them.Two terrorists play a game. They make moves in turn. Each move consists of the following operations. A player mines an airport, chooses a flight and flies away together with his colleague. After the take-off he actuates a radio-controlled fuse. As a result the airport that the terrorists have just left is destroyed, and all the flights to and from this airport are no longer possible. After the aircraft lands the other player makes his move, and so forth. One loses if one cannot make a move.
Given an initial list of flights and the number of an airport where the terrorists are at the start of the game, write a program which would determine who wins if the terrorists play a perfect game (each chooses the best move).
Input
The first line of an input contains two integers: N and K separated with a space. Here N is the number of airports (N <= 1000) and K is the number of an airport, which is the starting point of the game (1 <= K<= N). The next n-1 lines of the file contain pairs of integers separated with a space. These integers are numbers of airports, connected with a flight (all the flights are symmetric and are mentioned only once). There are at most 20 flights to each airport. Input data are always correct.Output
If the player who starts the game wins, the program should write: “First player wins flying to airport L” where L is the number of an airport to which the players should fly first. If there are more than one such airports, the program should find one of them that has the minimal number. Otherwise the program should write “First player loses”.Sample Input
4 33 2
3 1
1 4
Sample Output
First player wins flying to airport 2Source
Ural State University collegiate programming contest 2000题解
题意
给你一个N个结点N-1条边的无向图,飞机从结点K出发,两个人轮流坐飞机移动,走过的结点机场不能再走。无法移向下一个结点的人输,问第一个玩家能否获胜?如果能获胜,给出第一个玩家的第一步。
如下图,K=3,如果第一个玩家飞往2,第二个玩家不能再走,第二个玩家输。如果飞往1,第二个玩家只能飞往4,第一个玩家会输,但是两个玩家足够聪明,玩家一肯定选择飞往2,然后输出答案2即可。
附C++代码
#include<cstdio> #include<cstring> using namespace std; const int maxn=1010; bool Map[maxn][maxn],vis[maxn]; int N,L; bool Win(int k)//dfs { vis[k]=true; for(int i=1;i<=N;++i){ if(Map[k][i] && !vis[i]){ if(!Win(i)){ L=i; return true; } } } return false; } int main() { int K; while(~scanf("%d%d",&N,&K)) { memset(Map,0,sizeof(Map)); memset(vis,0,sizeof(vis)); int s,e; for(int i=1;i<=N-1;++i){ scanf("%d%d",&s,&e); Map[s][e]=Map[e][s]=1;//双向连通 } if(Win(K)) printf("First player wins flying to airport %d\n",L); else printf("First player loses\n"); } return 0; }
相关文章推荐
- POJ2599 A funny game (图博弈)
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- POJ 2599 A funny game
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- POJ 2599 A funny game (搜索,博弈)
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- POJ 2599 A funny game#树形SG(DFS实现)
- poj 2599 A funny game 博弈论
- POJ2599 A funny game (图博弈)
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- POJ 2599 A funny game(组合博弈 P/N态+记忆化搜索)
- [ACM] poj 2484 A Funny Game(对称博弈)
- poj 2484 A Funny Game 博弈(对称)
- POJ2484 A Funny Game
- POJ2484 A Funny Game (典型博弈论)
- POJ 2484 A Funny Game(博弈论)
- poj-2484 A Funny Game
- POJ 2484 A Funny Game(博弈论)