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 ...
随机推荐
- python time模块详解
python time模块详解 转自:http://blog.csdn.net/kiki113/article/details/4033017 python 的内嵌time模板翻译及说明 一.简介 ...
- POJ1260Pearls
http://poj.org/problem?id=1260 题意 :这个题大概是讲,给你几种等级不同的珠宝,然后告诉你它的数量和价值,等级是升序排列的,且随等级的升高价值也随之升高,但为了防止有的客 ...
- thinkphp多表关联并且分页
$db_prefix = C('DB_PREFIX'); $Model = new Model(); $data = $Model->table("{$db_prefix}ordern ...
- Java中List的排序
第一种方法,就是list中对象实现Comparable接口,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 ...
- sizeof运算符来获取各种数据类型在内存中所占字节数--gyy整理
C++并没有规定各种数据类型在内存中的存储大小,依赖于不同的编译器的不同而不同,要想获知当前编译器对各种数据类型分配的大小,可以通过sizeof运算符来获取. 使用方法1: sizeof(数据类型) ...
- 跨域使用jsonp 获取天气预报
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> ...
- 手机通过WIFI连上ZXV10 H618B路由器但不能上网问题的解决
前几天朋友帮忙拿到一个ZXV10 H618B路由器,一看需要12V供电,还好以前留下一个12V输出的DC充电器,关键时刻用上了,先大概下载了此路由器的用户手册,发现原来是08年的产品,都5年了. 开始 ...
- Web开发之tomcat配置及使用(环境变量设置及测试,一个简单的web应用实例)
Tomcat的配置及测试: 第一步:下载tomcat,然后解压到任意盘符 第二步:配置系统环境变量 tomcat解压到的D盘 (路径为: D:\tomcat), 配置环境变量: 启动tomcat需要两 ...
- 深入理解Android内存管理原理(六)
一般来说,程序使用内存的方式遵循先向操作系统申请一块内存,使用内存,使用完毕之后释放内存归还给操作系统.然而在传统的C/C++等要求显式释放内存的编程语言中,记得在合适的时候释放内存是一个很有难度的工 ...
- 扫描.net dll引用dll
最近升级系统里的NHibernate,从3.3到4,项目工程太多, 一个模块分bll,dal,model,web,test,10几个模块,就要60多dll,升级一次太头疼. 编译过后,有时候会有的dl ...