51NOD 1185 威佐夫游戏 V2(威佐夫博弈)

时间:2022-05-08
本文章向大家介绍51NOD 1185 威佐夫游戏 V2(威佐夫博弈),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1185 威佐夫游戏 V2

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题

有2堆石子。A B两个人轮流拿,A先拿。每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取。拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出2堆石子的数量,问最后谁能赢得比赛。

例如:2堆石子分别为3颗和5颗。那么不论A怎样拿,B都有对应的方法拿到最后1颗。

Input

第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行2个数分别是2堆石子的数量,中间用空格分隔。(1 <= N <= 10^18)

Output

共T行,如果A获胜输出A,如果B获胜输出B。

Input示例

3
3 5
3 4
1 9

Output示例

B
A
A

本来是个大水题,
结果这毒瘤出题人居然卡精度,
正解是把1.618拆开然后手动模拟乘法
#include<cstdio>
#include<cmath>
#include<iostream>
#define int long long 
using namespace std;
const  int MAXN=1e6+10;
int val[3]={618033988,749894848,204586834};
int mod=1000000000;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
main()
{
    #ifdef WIN32
    //freopen("a.in","r",stdin);
    #else
    #endif
    int QWQ=read();
    while(QWQ--)
    {
        int x=read(),y=read();
        if(x>y) swap(x,y);
        int temp=y-x;
        int a=temp/mod,b=temp%mod;//temp=a*mod+b
        int ans=b*val[2];
        ans=a*val[2]+b*val[1]+ans/mod;
        ans=a*val[1]+b*val[0]+ans/mod;
        ans=temp+a*val[0]+ans/mod;
        puts(ans==x?"B":"A");
    } 
    return 0;
}