Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 214    Accepted Submission(s): 150

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
 
Author
hanshuai@whu
 
Source
 
Recommend
notonlysuccess
 

想法太神了!!

1. 分成一个二分图
如果可以从A拿卡片到B,连一条从A到B的边。把所有box编号x满足((x%

3==0&&x%2==1) || x%3==1)这个条件的放左边,其他放右边,不难发现
a) 只有从左边到右边的边或从右到左的边。
b) 所有不能拿卡片出去的box都在左边。
2. 证明左边的box并不影响结果。假设当前从右边的局势来看属于输家的人为了
摆脱这种局面,从左边的某盒子A拿了n张卡片到B,因为B肯定有出去的边,对手
会从B再取走那n张卡片到左边,局面没有变化
3. 于是这就相当于所有右边的box在nim游戏。

其实只有1 3 4 是不能移动的。

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int T;
int n;
int a;
scanf("%d",&T);
int iCase = ;
while(T--)
{
iCase++;
scanf("%d",&n);
int sum = ;
for(int i = ;i <= n;i++)
{
scanf("%d",&a);
if((i%== && i%==) || i% == )
sum ^= a;
}
if(sum)printf("Case %d: Alice\n",iCase);
else printf("Case %d: Bob\n",iCase);
}
return ;
}

HDU 3389 Game(博弈)的更多相关文章

  1. HDU 3389 阶梯博弈变形

    n堆石子,每次选取两堆a!=b,(a+b)%2=1 && a!=b && 3|a+b,不能操作者输 选石子堆为奇数的等价于选取步数为奇数的,观察发现 1 3 4 是无法 ...

  2. hdu 3389 阶梯博弈

    题意:1-N带编号的盒子,当编号满足A>B && A非空 && (A + B) % 3 == 0 && (A + B) % 2 == 1则可以从A ...

  3. HDU 3389 (Nim博弈变形) Game

    参考了众巨巨的博客,现在重新整理一下自己的思路. 首先在纸上画了一下转移图: 1 3 4号盒子是不能够再转移卡片到其他盒子中去了的,其他盒子中的卡片经过若干步的转移最终也一定会转移到1 3 4号盒子中 ...

  4. HDU 4315 阶梯博弈变形

    n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋, ...

  5. HDU 1564 简单博弈 水

    n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...

  6. hdu 3389 Game (阶梯博弈)

    #include<stdio.h> int main() { int t,n,ans; int i,j,x; scanf("%d",&t); ;j<=t; ...

  7. HDU 3389 Game (阶梯博弈)

    Game Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status D ...

  8. 【hdu 3389】Game

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  9. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

随机推荐

  1. 搭建eova开发环境

    1.安装好maven 2.下载Eova项目解压到文件夹eova下 3.dos命令到eova文件夹下执行mvn eclipse:eclipse(注:构建eclipse项目命令) 4.修改*.tag文件错 ...

  2. 给 ecplise 配置struts2配置环境

    下面介绍在Eclipse中配置Struts2的过程: 一.下载Struts2,因为Struts2是开源的,百度或者google一下就可以找到下载地址.我下载的是struts-2.3.1.2版本 的,解 ...

  3. saltstack入门至放弃之salt安装部署

    学习了一段时间的saltstack,是时候记录下了.友提:学习环境是两台centos_7.2_x64机器 系统初始化: 两台机器执行以下脚本即可(友提:两台服务器的主机名配置在/etc/hosts中, ...

  4. CentOs7安装JDK/Tomcat/Git/Gradle

    安装Jdk: wget http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/j ...

  5. LCD实验学习笔记(二):head.S

    ARM加电后从0地址开始取指执行. 连接为bin文件时时,连接脚本lcd.lds指定将head.o放在开头,所以head.S就是系统起步的地方. head.S开头就是异常向量定义,0地址就是reset ...

  6. Jackson对多态和多子类序列化的处理配置

    目录 Jackson 多态类型的处理 Jackson Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 多态类型的处理 jacks ...

  7. android usb adb流程[转]

    android adb 概述 android adb的代码分为两部分: kernel层的代码在如下路径: drivers/usb/gadget/f_adb.c drivers/usb/gadget/a ...

  8. Mysql启动服务提示系统找不到指定的文件

    Mysql启动服务: C:\Windows\system32>net start mysql发生系统错误 2. 系统找不到指定的文件. 怎么还是报这个错?难道不是由于配置的原因?对,不是由于上面 ...

  9. mysql常用函数示例

    CREATE TABLE `orders` ( `OrderId` INT(10) NOT NULL AUTO_INCREMENT COMMENT '编号', `ProductName` VARCHA ...

  10. xshell命令大全

    suse linux 常用命令 (1)命令ls——列出文件 ls -la 给出当前目录下所有文件的一个长列表,包括以句点开头的“隐藏”文件 ls a* 列出当前目录下以字母a开头的所有文件 ls -l ...