首页 > 代码库 > 51nod 1185 || 51nod 1072 威佐夫博弈

51nod 1185 || 51nod 1072 威佐夫博弈

贴个模板:平常的跟高精度java的;

int:

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<set>#include<map>using namespace std;#define LL long long#define pi (4*atan(1.0))#define eps 1e-14#define bug(x)  cout<<"bug"<<x<<endl;const int N=1e6+10,M=1e6+10,inf=1e9+10;const LL mod=1e9+7;int main(){    double k=(sqrt(5.0)+1)/2;    int n;    scanf("%d",&n);    while(n--)    {        int a,b;        scanf("%d%d",&a,&b);        if(a>b)swap(a,b);        int x=(b-a)*k;        if(x==a)printf("B\n");        else printf("A\n");    }    return 0;}

 

java:

import java.util.*;import java.math.*;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        BigInteger k=new BigInteger("16180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374");        BigInteger p=new BigInteger("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");        int T;        T=cin.nextInt();        while(T--!=0)        {            BigInteger nn=cin.nextBigInteger();            BigInteger mm=cin.nextBigInteger();            BigInteger n=nn.min(mm);            BigInteger m=nn.max(mm);            BigInteger j=m.subtract(n);            j=j.multiply(k);            j=j.divide(p);            if(j.equals(n))                System.out.println("B");            else                 System.out.println("A");        }    }}

 

51nod 1185 || 51nod 1072 威佐夫博弈