poj - A funny game-2599

本文介绍了一种通过深度优先搜索算法解决恐怖分子游戏胜负判断问题的方法。游戏中两名恐怖分子在一个由N个机场组成的网络中轮流行动,每个机场都有唯一的连接路径。文章详细解释了如何编写C++代码来确定先手玩家是否能够赢得比赛,并给出了具体实现。

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 3
3 2
3 1
1 4

Sample Output

First player wins flying to airport 2

Source

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;
}
下载代码方式:https://pan.quark.cn/s/e6c2e312b658 在苹果公司的Mac操作系统环境中,当用户尝试安装非原厂驱动程序时,可能会遭遇系统无法正常启动的困境。这种情况常常源于名为.kext的内核扩展驱动程序存在兼容性问题或安装过程中出现失误。这份指南介绍了一种无需重新安装操作系统且能够保护所有用户数据的修复方法,这一方案对于先前许多面临类似挑战的用户而言,曾是极为棘手的情况。文档中提及的“用户模式启动”实际是指单用户模式,这种启动方式仅加载核心系统功能,而忽略图形用户界面及常规应用程序的加载。在单用户模式下,用户能够访问命令行界面,进而执行一系列修复指令。解决此问题的首要环节是验证存储设备是否存在故障,因为这是导致系统无法启动的常见诱因。借助终端指令`/sbin/fsck -f`,可以诊断并纠正文件系统层面的错误。倘若系统在启动过程中检测到文件系统异常,通常会自动执行`fsck`命令,然而,如果系统卡在进度条100%无法继续,手动运行该命令则显得尤为必要。指令`mount -uw /`的功能是将根目录切换为可读写状态,由于系统默认是以只读模式启动的。这一操作的目的是为了在不重新进入正常模式的前提下,对系统进行必要的调整。随后,文档提供了一个关键操作:对存在问题的驱动程序文件进行修改或更名。在Mac系统中,第三方驱动程序一般安装在`/Library/Extensions/`目录下。每个驱动程序都包含一个以.kext为后缀名的文件夹,例如在此案例中的AX88772.kext。通过命令行将故障的.kext文件更名(例如改为.kext.bak),可以临时禁用该驱动程序。这一操作需在命令行环境中完成,首先使用`cd /Library/Exte...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值