【博弈论】POJ[2348]Euclid's Game

好久不写博客了 最近在佳木斯培训 蒟蒻QAQ

今天来揭露一下这个虚伪的世界

【问题描述】
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7): an Stan wins.
给定a,b;每次用大的数减去小的数的任意倍,保证结果是自然数,已知Stan先手,求在最优策略下,先手胜负情况。

【问题分析】

bool dfs(int a,int b)
{
    if (a==0||b==0)
        return false;
    if (a<b)
        swap(a,b);
    for (int i=1;i*b<a;i++)
        if (!dfs(a-i*b,b))
            return true;
    return false;       
}

第一反应 但是发现RE了 这时候老师告诉我需要一些

奇淫巧技

然后我的AC代码是这样的

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b;
bool dfs(int a,int b)
{
    if (a==0||b==0)
        return false;
    if (a<b)
        swap(a,b);
    for (int i=a/b;i>0;i--)
        if (!dfs(a-i*b,b))
            return true;
    return false;       
}
int main()
{
    while(1)
    {
        scanf("%d%d",&a,&b);
        if (a==0&&b==0)
            break;
        if (dfs(a,b))
            printf("Stan wins\n");
        else
            printf("Ollie wins\n");
    }
    return 0;
}

这个虚伪的世界 再见!

妈的一个暴搜题QAQ

正解QAQ
如果先手必胜 那么满足条件 a%b==0
所以如果 状态为 a%b,b 那么先手必胜
那么想办法将状态转移到这里 即讨论[a/b]的取值情况
不断的将(a,b)转移到(a%b,b)即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值