A game

链接:https://ac.nowcoder.com/acm/problem/15867
来源:牛客网
题目描述
  Tony and Macle are good friends. One day they joined a birthday party together. Fortunately, they got the opportunity to have dinner with the princess, but only one person had the chance. So they decided to play a game to decide who could have dinner with the princess.
  The rules of the game are very simple. At first, there are n sticks. Each of exactly m meters in length. Each person takes turns. For one move the player chooses just one stick and cut it into several equal length sticks, and the length of each stick is an integer and no less than k. Each resulting part is also a stick which can be chosen in the future. The player who can’t make a move loses the game ,thus the other one win.
Macle make the first move.
输入描述:
  the first line contains tree integer n,m,k(1 <= n,m,k <= 109)
输出描述:
  print ‘Macle’ if Macle wins or ‘Tony’ if Tony wins,you should print everything without quotes.
示例1
输入
1 15 4
输出
Macle

示例2
输入
4 9 5
输出
Tony

题意

   n 个 m 米长的木棍,每次可以把他截为多个相同长度的木棍,但是长度没整数,并且大于等于 k ,不能能截取者败,Macle为先手,Tony后手,输出胜利者

思路

  多个相同NIM博弈变形,首先 偶数个相同时数异或值为 0 ,所以当 n%2 == 0 时,Yony胜。
  当 n%2 == 1 时,因为0 ^ n = n,所以我们只需要看一根木棍就行了,而他必败态时当木棍的长度为 [k ,2 * k - 1],也就是 m / k <=1,每次最截取,所以 我们从 m/k ~ 2 中寻找必胜态,如果 m 是 [k,2 * k - 1]中某个数的倍数,也就是存在 i ∈ [m/k,2],如果 m%i == 0 就是先手必胜态,反之必败。
AC代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<vector>
#include<algorithm>
#include<sstream>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int maxn = 1010;
const int k = 1000;
int main(void)
{
    int n,m,k;

    cin>>n>>m>>k;
    if(n%2==0)  printf("Tony\n");
    else{
        bool ans = false;
        for(int i=m/k;i>1;i--){
            if(m%i==0){
                ans = true;
                break;
            }
        }
        if(ans) printf("Macle\n");
        else printf("Tony\n");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逃夭丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值