Gym 100827G Number Game (博弈)
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 (博弈)的更多相关文章
- HDU 5623 KK's Number (博弈DP)
KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...
- UVA 1558 - Number Game(博弈dp)
UVA 1558 - Number Game 题目链接 题意:20之内的数字,每次能够选一个数字,然后它的倍数,还有其它已选数的倍数组合的数都不能再选,谁先不能选数谁就输了,问赢的方法 思路:利用dp ...
- Gym 100512F Funny Game (博弈+数论)
题意:给两个数 n,m,让你把它们分成 全是1,每次操作只能分成几份相等的,求哪一个分的次数最多. 析:很明显,每次都除以最小的约数是最优的. 代码如下: #pragma comment(linker ...
- Codeforces Round #651 (Div. 2) C. Number Game (博弈,数学)
题意:对于正整数\(n\),每次可以选择使它变为\(n-1\)或者\(n/t\) (\(n\ mod\ t=0\)且\(t\)为奇数),当\(n=1\)时便不可以再取,问先手赢还是后手赢. 题解:首先 ...
- 2017 ACM-ICPC EC-Final ShangHai 东亚洲大陆-上海
比赛链接:传送门 Gym 101775A Chat Group(签到:待补) Gym 101775B Scapegoat(待补) Gym 101775C Traffic Light(贪心+思维) 思路 ...
- 2016-2017 ACM-ICPC CHINA-Final
A Gym 101194A Number Theory Problem 7 的二进制是111,2k-1 的二进制是 k 个 1.所以 k 能被 3 整除时 2k-1 才能被 7 整除. #includ ...
- 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 ...
- Gym - 101350E Competitive Seagulls (博弈)
There are two seagulls playing a very peculiar game. First they line up N unit squares in a line, al ...
- 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 ...
随机推荐
- POJ3207+tarjan+2-sat
/* 2-sat 题意:给定一个圆,圆上一些点.两点一线.现给出一些线,这些线可以在圆内连起来,也可以在圆外. 问有没有可能所有的线画完 且 不出现相交. 思路:把线画在圆内或圆外 看成一个组合.其它 ...
- jmeter 一个可能引起性能严重下降的断言设置
在添加断言时一定要注意: 1. 红框部分选择 "响应文本", 2. 要断言的内容越短越好
- linux 磁盘读写性能测试
1. 测试读取速度 haparm -Tt /dev/xxx 1.1 获取硬盘设备名称: fdisk -l Disk /dev/xvdf: 365.0 GB, 365041287168 bytes 25 ...
- sql快捷键
请柬:https://msdn.microsoft.com/zh-cn/library/ms174205.aspx
- QDialog之屏蔽Esc键(过滤,或者丢弃)
http://blog.csdn.net/u011012932/article/details/50357323
- 107. Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- mysql 查看表的类型
MySQL 数据表主要支持六种类型 ,分别是:BDB.HEAP.ISAM.MERGE.MYISAM.InnoBDB. 这六种又分为两类,一类是”事务安全型”(transaction-safe),包括B ...
- BZOJ2668: [cqoi2012]交换棋子
题解: 可以戳这里:http://www.cnblogs.com/zig-zag/archive/2013/04/21/3033485.html 其实自己yy一下就知道这样建图的正确性了. 感觉太神奇 ...
- amoeba安装与实现amoeba for mysql读写分离
运行环境 l CentOS6.3 l Jdk1.6.0_30 l amoeba-mysql-binary-2.2.0 l amoeba:192.168.88.17 l master1:192 ...
- oracle静态与动态监听
在运行lsnrctl命令的status时,常会看到如下返回值: 服务“test”包含1个例程. 例程"mydata",状态 UNKOWN,包含此服务的一个处理程序... 服务 ...