码迷,mamicode.com
首页 > 其他好文 > 详细

1072 威佐夫游戏(v1)

时间:2017-10-06 12:24:04      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:color   分享   ext   http   span   icon   fine   problem   online   

1072 威佐夫游戏技术分享51NOD基础题

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
 
有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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std ; 

#define LL long long

void swap( LL &a1 ,LL  &a2){
    LL temp = a1 ; 
    a1 = a2 ;  
    a2 = temp ; 
}

int main(){
    LL a , b ; 
    int t ; 
    scanf("%d" , &t) ; 
    while(t--){
        scanf("%lld%lld" , &a , &b) ; 
        if(a > b)
            swap(a , b ) ; 
        double re = (1 + sqrt(5))/2 ;// 黄金分割
        //if((LL)(re*(b-a))  == a )//都行 
        if(floor(re*(b-a)) == a)
        {
            printf("B\n") ; 
        }  else {
            printf("A\n") ; 
        }
    }
    return 0 ; 
} 

 

1072 威佐夫游戏(v1)

标签:color   分享   ext   http   span   icon   fine   problem   online   

原文地址:http://www.cnblogs.com/yi-ye-zhi-qiu/p/7631241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!