zoukankan      html  css  js  c++  java
  • 51Nod 1185 威佐夫游戏 V2

    有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
    说实话,要不是看题解,真的是不知道还有这样的一种减少精度的做法。还是要多练。
    //Asimple
    #include <bits/stdc++.h>
    //#define INF 0x3fffffff
    #define swap(a,b,t) t = a, a = b, b = t
    #define CLS(a, v) memset(a, v, sizeof(a))
    #define debug(a)  cout << #a << " = "  << a <<endl
    #define test() cout<<"=========="<<endl
    using namespace std;
    typedef long long ll;
    const int maxn = 50000+5;
    const double PI=acos(-1.0);
    const ll mod = 1000000000;
    const int INF = ( 1 << 20 ) ;
    const int dx[] = {-1, 0, 1, 0};  
    const int dy[] = { 0,-1, 0, 1}; 
    ll n, m, res, ans, len, T, k, num, sum, t;
    ll te[] = {618033988,749894848,204586834};
    //ll mod;
    
    void input() {
        ios_base::sync_with_stdio(false);
        cin >> T;
        while( T -- ){
            cin >> n >> m;
            if( n>m ) { t = n; n = m; m = t; }
            res = m-n;
            k = res/mod, t = res%mod;
            sum = t*te[2];
            sum = k*te[2]+t*te[1]+sum/mod;
            sum = k*te[1]+t*te[0]+sum/mod;
            sum = res+k*te[0] + sum/mod;
            if( sum == n ) cout << "B" << endl;
            else cout << "A" << endl;
        }
    }
    
    int main(){
        input();
        return 0;
    }
  • 相关阅读:
    如何使用NuGet package .nupkg文件?
    利用Z.Expressions.Eval表达式求值
    表达式实现填写“阶段标记”属性
    NX导入DWG失败
    简单工厂模式(Simple Factory Pattern)
    电脑装系统蓝屏未解决
    idea intellij 配置总结
    poiexcel 笔记
    Springboot
    Springboot--maven命令子模块单独打包
  • 原文地址:https://www.cnblogs.com/Asimple/p/7637744.html
Copyright © 2011-2022 走看看