新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛) G chess(威佐夫博奕)

A single chess queen is placed somewhere on a  grid of 10000*10000 squares.Lao Wang and Xiao Ren ready to play a game The rules are player can move the queen towards the lower left corner of the grid: south, west, or southwest, any number of steps. The winner is the player who moves the queen into the southwest corner.If you let the old Xiao Ren first chess .Suppose they will use the best strategy who will win the game?


输入描述:
The input will consist of a series of pairs of integers a and b, Indicates the distance from the west boundary and the distance from the south boundary.
输出描述:
For each pair of input integers a and b you should output the winner's name in one line;
示例1
输入
1 2
3 5
1 1
3 2
输出
Lao Wang
Lao Wang
Xiao Ren

Xiao Ren

题意:一个棋盘,老王和小人下棋,棋子只能往下或者往左或者往左下走,小人先走,问谁能先到左下最左下角

思路:威佐夫博奕模板https://www.cnblogs.com/luowentao/p/8977029.html

https://blog.csdn.net/deepseazbw/article/details/77160818

直接判断是否为奇异局势

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        if(n>m)swap(n,m);
        int x=(1+sqrt(5))/2*(m-n);
        if(n==x) printf("Lao Wang\n");
        else printf("Xiao Ren\n");
    }
    return 0;
}

构造出奇异局势

#include<bits/stdc++.h>
 
using namespace std;
const int N = 1e5+5;
int p[N];
int main()
{
    int a,b;
    p[1]=2;
    p[2]=1;
    //构造出奇异局势
    for(int i=1,temp=1; i<10001; i++)
    {
        if(p[i]!=0)
        {
            temp++;
        }
        if(p[i]==0)
        {
            temp=temp+2;
            p[i]=temp;
            p[temp]=i;
        }
        if(temp>=10000)
            break;
    }
 
    while(scanf("%d %d",&a,&b)==2)
    {
        if(p[a]==b)
            printf("Lao Wang\n");
        else
            printf("Xiao Ren\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/deepseazbw/article/details/80163157