Number Game

Alice and Bob are playing a game on a line of N squares. The line is initially populated with one of each of the numbers from 1 to N. Alice and Bob take turns removing a single number from the line, subject to the restriction that a number may only be removed if it is not bordered by a higher number on either side. When the number is removed, the square that contained it is now empty. The winner is the player who removes the 1 from the line. Given an initial configuration, who will win, assuming Alice goes first and both of them play optimally?

Input
Input begins with a line with a single integer T, 1 ≤ T ≤ 100, denoting the number of test cases. Each test case begins with a line with a single integer N, 1 ≤ N ≤ 100, denoting the size of the line. Next is a line with the numbers from 1 to N, space separated, giving the numbers in line
order from left to right.

Output
For each test case, print the name of the winning player on a single line.

Sample Input

4 4
2 1 3 4
4
1 3 2 4
3
1 3 2
6
2 5 1 6 4 3

Sample Output

Bob
Alice
Bob
Alice

题意:输入一个N, 然后给一个1~N的数列。两个人轮流拿数字,当一个数字两边没有比它大的数字的时候(旁边是空格也可以),这个数字就可以被拿走。

题解:

考虑到如果要拿1,就要先把1旁边的两个数都拿走,那么如果1旁边两个数其中的一个已经被拿走,两个人肯定是不想拿剩下的一个数,所以此时所走的步数已经确定。Alice作为先手,优势就是选择两数之一。1在旁边特殊考虑一下,其实原理是一样的。

画个图表示下(略抽象):

附上几组数据:

8
7 3 5 2 4 1 6 8
6
1 5 3 4 2 6
7
7 2 4 6 3 1 5
6
1 5 3 4 2 6
5
3 4 1 5 2 Bob
Alice
Alice
Alice
Bob

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
int a[N]; // 窝乃辣鸡
// 感谢小杭=.= bool MDZZ()
{
int n;
scanf("%d", &n);
int pone, pl, pr;
pl = ; pr = n+;
for (int i = ; i <= n; ++i) {
scanf("%d", a+i);
if (a[i] == ) pone = i;
}
for (int i = pone - ; i > ; --i) {
if (a[i] < a[i-]) { pl = i-; break; }
}
for (int i = pone + ; i < n; ++i) {
if (a[i] < a[i+]) { pr = i+; break; }
}
int ex = (n - pr + ) + (pl); int ls = pone - pl - ; // 左边中间的
int rs = pr - pone - ; // 右边中间的 if (n == ) return true; // 如果1在最左边或者最右边
if (pone == || pone == n) {
if ((ex+) % == ) return true;
}
// 1不在边上
else{
bool f = false;
// 能先拿1左边的数
if ((pl == ) || (ls > )) {
if ((ex+ls+) % == ) return true;
f = true;
}
// 能先拿1右边的数
if ((pr == n+) || (rs > )) {
if ((ex+rs+) % == ) return true;
f = true;
}
// 1左右的数都不能拿 必须把全部的拿走才行
if (!f && n % == ) return true;
}
return false;
} int main()
{
int t;
scanf("%d", &t);
while (t--) puts(MDZZ() ? "Alice" : "Bob");
return ;
}

Gym 100827G Number Game (博弈)的更多相关文章

  1. HDU 5623 KK's Number (博弈DP)

    KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...

  2. UVA 1558 - Number Game(博弈dp)

    UVA 1558 - Number Game 题目链接 题意:20之内的数字,每次能够选一个数字,然后它的倍数,还有其它已选数的倍数组合的数都不能再选,谁先不能选数谁就输了,问赢的方法 思路:利用dp ...

  3. Gym 100512F Funny Game (博弈+数论)

    题意:给两个数 n,m,让你把它们分成 全是1,每次操作只能分成几份相等的,求哪一个分的次数最多. 析:很明显,每次都除以最小的约数是最优的. 代码如下: #pragma comment(linker ...

  4. Codeforces Round #651 (Div. 2) C. Number Game (博弈,数学)

    题意:对于正整数\(n\),每次可以选择使它变为\(n-1\)或者\(n/t\) (\(n\ mod\ t=0\)且\(t\)为奇数),当\(n=1\)时便不可以再取,问先手赢还是后手赢. 题解:首先 ...

  5. 2017 ACM-ICPC EC-Final ShangHai 东亚洲大陆-上海

    比赛链接:传送门 Gym 101775A Chat Group(签到:待补) Gym 101775B Scapegoat(待补) Gym 101775C Traffic Light(贪心+思维) 思路 ...

  6. 2016-2017 ACM-ICPC CHINA-Final

    A Gym 101194A Number Theory Problem 7 的二进制是111,2k-1 的二进制是 k 个 1.所以 k 能被 3 整除时 2k-1 才能被 7 整除. #includ ...

  7. Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】

    G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...

  8. Gym - 101350E Competitive Seagulls (博弈)

    There are two seagulls playing a very peculiar game. First they line up N unit squares in a line, al ...

  9. Gym 101194A / UVALive 7897 - Number Theory Problem - [找规律水题][2016 EC-Final Problem A]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

随机推荐

  1. chardet安装

    1.下载 chardet-2.2.1.tar.gz (md5)   https://pypi.python.org/pypi/chardet#downloads 2.解压至C:\Python27\Li ...

  2. Windows调试的基石——符号(1)

    当应用程序被链接以后,代码被逐一地翻译为一个个的地址,优化以后的代码可能初看起来更是面目全非.每当我们使用vs或者windbg等微软的调试工具进行调试的时候,我们可以方便地使用变量名来查看内存.可以使 ...

  3. hdu 4672 Present Day, Present Time 博弈论

    看了解题报告才知道怎么做!! 题意:有 N 堆石子和 M 个石子回收站,每回合操作的人可以选择一堆石子,从中拿出一些 放到石子回收站里(可以放进多个回收站,每个回收站可以使用无数次),但每个石子回收站 ...

  4. redis面试

    1. 使用Redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...

  5. atomikos的Jta配置

    配置说明见: http://www.atomikos.com/Documentation/JtaProperties atomikos的一些配置,文档中说明的比较清楚,有两个属性配置不太明确:com. ...

  6. Oracl 动态执行表不可访问,本会话的自动统计被禁止

    oracle ---建立SQL窗体 写入 select * from tableA; 弹出错误窗口 : 动态执行表不可访问,本会话的自动统计被禁止.在执行菜单里你可以禁止统计,或在v$session, ...

  7. Android开发之MediaPlayer和SurfaceView组成视频播放器

    SurfaceView 使用双缓冲技术 是个重量级的组件 只要不可见,就不会创建,可见时,才会创建 只要不可见,就会销毁 SurfaceView一旦不可见,就会被销毁,一旦可见,就会被创建,销毁时停止 ...

  8. Codeforces Round #306 (Div. 2)

    A. Two Substrings You are given string s. Your task is to determine if the given string s contains t ...

  9. RPi 2B python opencv camera demo example

    /************************************************************************************** * RPi 2B pyt ...

  10. acdream 瑶瑶带你玩激光坦克 (模拟)

    瑶瑶带你玩激光坦克 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 256000/128000KB (Java/Others) Submi ...