Game HDU - 3389 (博弈论)

时间:2022-12-26 12:05:02
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.

InputThe 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.OutputFor 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 题意:
编号可以满足B<A && (A+B)%2=1 && (A+B)%3=0就可以把石子从A移动到B。 思路:
阶梯博弈 问题导入我就不BB了,普通阶梯博弈的结论就是奇数阶的异或和。
1.1 如果先手必败,挪动偶数阶的石子,对方肯定将挪动的石子再次挪到偶数阶上,保持你的必败状态。
1.2 如果先手必败,挪动奇数阶的石子,相当于取走nim博弈中的石子,你的必败态并未改变。
2.1 如果先手必胜,挪动偶数阶的石子。。。。。你没有必要这么做。。
2.2 如果先手必胜,挪动奇数阶的石子,就把问题1.1,1.2丢给了对方。 这个题画个图,变形一下就行了。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int n;
int num[maxn];
int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); int T;
int cases=;
scanf("%d",&T);
while(T--){
cases++;
scanf("%d",&n);
int ans=,x;
for(int i=;i<=n;i++){
scanf("%d",&x);
if(i%==||i%==||i%==){
ans^=x;
}
}
printf("Case %d: ",cases);
if(ans){printf("Alice\n");}
else printf("Bob\n");
} return ;
}

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

  1. HDU 3389 阶梯博弈变形

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

  2. 悼念512汶川大地震遇难同胞——选拔志愿者 HDU 2188 博弈论 巴什博奕

    悼念512汶川大地震遇难同胞--选拔志愿者 HDU 2188 博弈论 巴什博奕 题意 对于四川同胞遭受的灾难,全国人民纷纷伸出援助之手,几乎每个省市都派出了大量的救援人员,这其中包括抢险救灾的武警部队 ...

  3. 取(2堆)石子游戏 HDU 2177 博弈论

    取(2堆)石子游戏 HDU 2177 博弈论 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中 ...

  4. 取石子游戏 HDU 1527 博弈论 威佐夫博弈

    取石子游戏 HDU 1527 博弈论 威佐夫博弈 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两 ...

  5. hdu 3389 Game 博弈论

    思路: 其本质为阶梯博弈; 阶梯博弈:博弈在一列阶梯上进行,每个阶梯上放着自然数个点,两个人进行阶梯博弈...     每一步则是将一个集体上的若干个点( >=1 )移到前面去,最后没有点可以移 ...

  6. 【hdu 3389】Game

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

  7. hdu 3389 Game (阶梯博弈)

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

  8. HDU 3389 &lpar;Nim博弈变形&rpar; Game

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

  9. hdu 3389 阶梯博弈

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

随机推荐

  1. 代理方法keywordAction与Fun的使用

    代理是一种特殊的,指向某个方法模块所在的地址.一般来讲,那个方法模块,能够是一个普通的方法,很多其它的时候,是一团匿名的lamda表达式,即一个匿名方法.如今简单理解一下代理的简写方式,即Action ...

  2. 深入理解CSS3 Animation 帧动画(转)

    CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是真的沉淀下来仔细的去深入CSS3动画的各个属性发现还是很深的,这里就写下关于帧动 ...

  3. WPF的一些感悟

    第一天在博客园写东西,只写一些自己对WPF稚嫩的理解和感悟. 1.Code Snippet代码简写工具 可以创建自己的代码模板管理器——>>>工具菜单,代码片段管理器 考出现有的+更 ...

  4. SetWindowPos和SetForegroundWindow

    There are many closely-related concepts involved, and related terms are often misused, even in the o ...

  5. Math&period;max&period;apply&lpar;null&comma;arr&rpar;求最大值

    1.首先了解一下call和apply call 和 apply 的第一个参数是null/undefined时函数内的this指向window 或global call/apply 用来改变函数的执行上 ...

  6. opencv图像识别技术在自动化测试中的应用

    在自动化测试中,基于xpath.js选择器.css选择器进行元素定位及判定的技术已经比较成熟.在实际应用中,无论是web端还是移动端,仍有很多时候需要根据页面内容.页面中的图像进行定位及判定,这里介绍 ...

  7. Java实现快速批量移动文件

    文件移动是计算机资源管理常用的一个操作,这在操作系统中可以通过文件的剪切与复制或鼠标拖动来实现.但是在Java文件的编程实现中,大多是通过复制文件到目的地,再删除所有文件来实现的.这对于小文件来说看不 ...

  8. Python——你应该知道这些

    1. Python的出生 1989年 Guido van Rossum开始编写Python语言编辑器(龟叔为了打发无聊的圣诞节) 1991年 第一个Python编译器诞生(正式诞生) 1994年 Py ...

  9. 记录下push推送优化改进点

    一)自主研发的push服务的特点及优势: 1) 消息回执确认(ack); 2) 有效期推送(设置消息的有效期); 3) 精准推送(设置设备组别推送); 4) 下发任务分解(拆分任务,多进程); 5) ...

  10. 【BZOJ3834】&lbrack;Poi2014&rsqb;Solar Panels 分块好题

    [BZOJ3834][Poi2014]Solar Panels Description Having decided to invest in renewable energy, Byteasar s ...