zoukankan      html  css  js  c++  java
  • 2015苏州大学ACM-ICPC集训队选拔赛(1) 1006

    取金币

    Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
    Total Submission(s) : 102   Accepted Submission(s) : 43

    Font: Times New Roman | Verdana | Georgia

    Font Size: ← →

    Problem Description

    有一枚金币,其左边有a个猫粮,右边有b个猫粮,每次可以从最左或者最右取一个物品,先取到金币的一方获胜。

    Input

    第一行一个数T,表示测试数据组数(1 <= T <= 100)
    接下来T行,每行有两个整数a和b,0 <=a, b<= 1e9

    Output

    如果先手获胜输出“First”(引号不输出), 否则输出“Second”(引号不输出)。

    Sample Input

    2
    0 3
    1 1

    Sample Output

    First
    Second

    Author

    Tong Wei
    首先是个巴什博弈但又有点不同
    首先 1 1 这种后手一定是胜利的,因为先手不管取哪边的猫粮,都会有一边空的,那么后手可以在空的那一边把金币拿走
    当然 0 0是先手胜利
    好,接下来就是一个巴什博弈了,谁先取完留下 1 1 这个状态,谁就胜利了  那么我们把两边的猫粮加起来减去2(最终状态1 1的和是2) 然后利用公式就好了
    #include<stdio.h>
    //#include<bits/stdc++.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<queue>
    #include<map>
    #include<vector>
    #include<algorithm>
    #include<limits.h>
    #define inf 0x3fffffff
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    using namespace std;
    int a;
    int main()
    {
        int t;
        int n,m;
        while(cin>>t)
        {
            while(t--)
            {
                cin>>n>>m;
                if(n==0||m==0)
                {
                    puts("First");
                }
                else if(n==1&&m==1)
                {
                    puts("Second");
                }
                else
                {
                    if((n+m-2)%2!=0)
                    {
                        puts("First");
                    }
                    else
                    {
                        puts("Second");
                    }
                }
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    hdu 4825 Xor Sum (01 Trie)
    hdu 5877 Weak Pair (Treap)
    bzoj 1861: [Zjoi2006]Book 书架 (splay)
    bzoj 1503: [NOI2004]郁闷的出纳员 (splay)
    hihocoder#1333 : 平衡树·Splay2 (区间操作)
    「BZOJ1251」序列终结者 (splay 区间操作)
    二进制运算符的相关运算
    Bzoj 1085: [SCOI2005]骑士精神 (dfs)
    Bzoj 1083: [SCOI2005]繁忙的都市 (最小生成树)
    Bzoj 1088: [SCOI2005]扫雷Mine (DP)
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5076808.html
Copyright © 2011-2022 走看看