高精度威佐夫博弈

链接:http://www.51nod.com/Challenge/Problem.html#!#problemId=1185

本来威佐夫博弈只用a*(sqrt(5)+1)/2就行了,可这题精度太高,必须将0.618的精度再扩大很多倍

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
LL tmp[3] = {618033988,749894848,204586834};
LL MOD = 1000000000;
int main()
{
    int T;
    LL m, n;
    cin>>T;
    while(T--)
    {
        cin>>m>>n;
        if(m < n)
            swap(n, m);
        LL cha = m - n;
        LL ta = cha/MOD, tb = cha%MOD;
        LL tp = tb*tmp[2];
        tp = ta*tmp[2] + tb*tmp[1] + tp/MOD;
        tp = ta*tmp[1] + tb*tmp[0] + tp/MOD;
        tp = cha + ta*tmp[0] + tp/MOD;
        if(tp == n)
            puts("B");
        else
            puts("A");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值