新疆大学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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值