经典博弈题,比V1数据范围大了很多,像V1一样单纯改变n的数据类型,运算时会因为误失精度而WA掉。通过乘法模拟精度得到解决(很不错的思路,模拟很优雅~)。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int t;
ll tmp[3]={618033988,749894848,204586834};
ll mod=1e9;
int main()
{
cin>>t;
while(t--){
ll a,b,n;
cin>>a>>b;
if(a>b)swap(a,b);
n=b-a;
ll fir=n/mod,sec=n%mod,sum;
//通过乘法模拟精度
sum=sec*tmp[2];
sum=fir*tmp[2]+sec*tmp[1]+sum/mod;
sum=fir*tmp[1]+sec*tmp[0]+sum/mod;
sum=fir*tmp[0]+sum/mod;
sum+=n;
if(sum==a)puts("B");
else puts("A");
}
return 0;
}