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. 用 OneAPM Cloud Insight 监控 Docker 性能

    Docker 是构建和部署软件的一个新兴的轻量级的平台,也是一个减轻替代虚拟机的容器.Docker 通过给开发者提供兼容不同环境的镜像,成为解决现代基础设施的持续交付的一个流行的解决方案. 和虚拟机一 ...

  2. HDU 1031 Design T-Shirt

    http://acm.hdu.edu.cn/showproblem.php?pid=1031 题意 :n个人,每个人对m件衣服打分,每个人对第 i 件衣服的打分要加起来,选取和前 k 高的输出他们的编 ...

  3. 186. Reverse Words in a String II

    题目: Given an input string, reverse the string word by word. A word is defined as a sequence of non-s ...

  4. James搭建邮件服务器

    来源:http://chenfengcn.iteye.com/blog/356874   1 关于James与Javamail Apache James(Java Apache Mail Enterp ...

  5. MAX-HEAPIFY(2/3n的疑惑)

    Q: In CLRS, third Edition, on page 155, it is given that in MAX-HEAPIFY, The children’s subtrees eac ...

  6. 转: Linux 技巧:让进程在后台可靠运行的几种方法

    我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络断开 ...

  7. 转 Android adb root权限

    永久root带文件 因为开发需要,我经常会用到adb这个工具(Android Debug Bridge),我们都知道adb shell默认是没有root权限的,修改系统文件就很不方便了,adb pus ...

  8. 【JAVA】别特注意,POI中getLastRowNum() 和getLastCellNum()的区别

    hssfSheet.getLastRowNum();.行标,比行数小1 hssfSheet.getRow(k).getLastCellNum();//获取列数,比最后一列列标大1 行标.列标都以0开始 ...

  9. LinkedBlockingQueue

    LinkedBlockingQueue是一个基于已链接节点的.范围任意的blocking queue的实现.    此队列按 FIFO(先进先出)排序元素.队列的头部 是在队列中时间最长的元素.队列的 ...

  10. BZOJ3792: 跑步

    题解: 感觉被坑出翔... 显然我们把矩阵乘法中的点当成原图中的边就可以了. 先写opertor 在struct里面居然只能带一个变量?... 放到外面,然后还得加引用? 然后题目描述不清,重边怎么算 ...