zoukankan      html  css  js  c++  java
  • 1072 威佐夫游戏

    有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 <= 2000000)
    Output
    共T行,如果A获胜输出A,如果B获胜输出B。
    Input示例
    3
    3 5
    3 4
    1 9
    Output示例
    B
    A
    A
     分析:这题一开始ZZ了,其实就是推个公式的事。。
    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <deque>
    #include <map>
    #define range(i,a,b) for(int i=a;i<=b;++i)
    #define LL long long
    #define rerange(i,a,b) for(int i=a;i>=b;--i)
    #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
    using namespace std;
    int t;
    void init() {
        cin>>t;
    }
    void solve(){
        while(t--){
            LL n,m;
            cin>>n>>m;
            if(n>m){
                int tmp=n;
                n=m;
                m=tmp;
            }
            LL tmp=floor((m-n)*(1+sqrt(5))/2);
            cout<<(tmp!=n?"A":"B")<<endl;
        }
    }
    int main() {
        init();
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    为什么页面设计宽度要控制在960px
    RRDtool运用
    cacti监控jvm
    cacti安装
    rConfig v3.9.2 授权认证与未授权RCE (CVE-2019-16663) 、(CVE-2019-16662)
    Linux安全学习
    Github-Dorks与辅助工具
    警方破获超大DDoS黑产案,20万个僵尸网络运营商被抓
    SRC漏洞挖掘
    威胁情报木马病毒样本搜集
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9331093.html
Copyright © 2011-2022 走看看