zoukankan      html  css  js  c++  java
  • HDU3389 Game

    Problem Description
    Bob and Alice are playing a new game. There are n boxes which have been numbered from 1 to n. Each box is either empty or contains several cards. Bob and Alice move the cards in turn. In each turn the corresponding player should choose a non-empty box A and choose another box B that B<A && (A+B)%2=1 && (A+B)%3=0. Then, take an arbitrary number (but not zero) of cards from box A to box B. The last one who can do a legal move wins. Alice is the first player. Please predict who will win the game.
    Input
    The first line contains an integer T (T<=100) indicating the number of test cases. The first line of each test case contains an integer n (1<=n<=10000). The second line has n integers which will not be bigger than 100. The i-th integer indicates the number of cards in the i-th box.
    Output
    For each test case, print the case number and the winner's name in a single line. Follow the format of the sample output.
    Sample Input
    2
    2
    1 2
    7
    1 3 3 2 2 1 2
    Sample Output
    Case 1: Alice
    Case 2: Bob
    根据staircase nim游戏的结论
    假设移动的终点为0,那么只要考虑奇数位的Nim和就行了
    如果不是按位移动的,那么就变成距离终点步数为奇数的Nim和
    画图归纳,发现当i%6等于0,2,5时,到终点步数为奇数
    取那些位的Nim和
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 int ans,n;
     8 int gi()
     9 {
    10   int x=0;char ch=getchar();
    11   while (ch<'0'||ch>'9') ch=getchar();
    12   while (ch>='0'&&ch<='9')
    13     {
    14       x=x*10+ch-'0';
    15       ch=getchar();
    16     }
    17   return x;
    18 }
    19 int main()
    20 {int i,T,TT,x;
    21   cin>>T;
    22   TT=T;
    23   while (T--)
    24     {
    25       cin>>n;
    26       ans=0;
    27       for (i=1;i<=n;i++)
    28     {
    29       x=gi();
    30       if (i%6==0||i%6==2||i%6==5)
    31         ans^=x;
    32     }
    33       if (ans) printf("Case %d: Alice
    ",TT-T);
    34       else printf("Case %d: Bob
    ",TT-T);
    35     }
    36 }
     
  • 相关阅读:
    MySQL涉及连接的问题
    SQL注入的问题
    如果有一个特别大的访问量到数据库上,怎么做优化?主从复制、读写分离
    MySQL,优化查询的方法
    Solr搜索引擎
    线程安全与锁优化
    Java与线程
    Java内存模型
    你不会成为数据科学家的9个原因:数据科学是一个艰难的领域,请做好准备
    深度学习中的激活函数完全指南:在数据科学的诸多曲线上进行现代之旅
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/8523094.html
Copyright © 2011-2022 走看看