CodeForces - 1162E Thanos Nim (博弈论)
Alice and Bob are playing a game with nn piles of stones. It is guaranteed that nn is an even number. The ii-th pile has aiai stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exactly n2n2 nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than n2n2 nonempty piles).
Given the starting configuration, determine who will win the game.
Input
The first line contains one integer nn (2≤n≤502≤n≤50) — the number of piles. It is guaranteed that nn is an even number.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤501≤ai≤50) — the number of stones in the piles.
Output
Print a single string "Alice" if Alice wins; otherwise, print "Bob" (without double quotes).
Examples
2
8 8
Bob
4
3 1 4 1
Alice 题意:
给偶数(n)堆石子,每一步必须取n/2堆石子中的任意多个,当场上不足n/2堆石子时,当前玩家失败,问谁是最后的获胜者。
思路:
如果有任何一堆石子已经被拿空,那么只需要直接取空n/2堆石子,便可以获胜。
所以作为后手,如果能维护石子数量最小的堆数量大于N,便可以取胜,因为在这种情况下,石子数越来越少,先手总会拿空一堆。
#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 debug(a,i) cout<<#a<<"["<<i<<"] = "<<a[i]<<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 maxm = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int num[maxn];
int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&num[i]);
}
sort(num+,num++n);
if(num[n/+]!=num[]){printf("Alice\n");}
else printf("Bob\n");
return ;
}
CodeForces - 1162E Thanos Nim (博弈论)的更多相关文章
- Codeforces 1162E Thanos Nim(博弈)
一道有意思的博弈题.首先我们考虑一种必败情况,那就是有一方拿光了一堆石子,显然对方是必胜,此时对方可以全部拿走其中的n/2,那么轮到自己时就没有n/2堆,所以此时是必败态.我们先对所有石子堆sort, ...
- (转载)Nim博弈论
最近补上次参加2019西安邀请赛的题,其中的E题出现了Nim博弈论,今天打算好好看看Nim博弈论,在网上看到这篇总结得超级好的博客,就转载了过来. 转载:https://www.cnblogs.com ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- codeforces 15C. Industrial Nim
题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...
- hdu 3032 Nim or not Nim? 博弈论
这题是Lasker’s Nim. Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g( ...
- POJ2068 Nim 博弈论 dp
http://poj.org/problem?id=2068 博弈论的动态规划,依然是根据必胜点和必输点的定义,才明白过来博弈论的dp和sg函数差不多完全是两个概念(前者包含后者),sg函数只是mex ...
- Codeforces 786A Berzerk(博弈论)
[题目链接] http://codeforces.com/problemset/problem/786/A [题目大意] 有两个人,每个人有一个数集,里面有一些数,现在有一个环,有个棋子放在1, 有个 ...
- Codeforces 15C Industrial Nim 简单的游戏
主题链接:点击打开链接 意甲冠军: 特定n 下列n行,每一行2的数量u v 表达v礧:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先依据Nim的博弈结论 把全部数都异或一下, ...
- Forethought Future Cup - Final Round (Onsite Finalists Only) C. Thanos Nim 题解(博弈+思维)
题目链接 题目大意 给你n堆石子(n为偶数),两个人玩游戏,每次选取n/2堆不为0的石子,然后从这n/2堆石子中丢掉一些石子(每一堆丢弃的石子数量可以不一样,但不能为0),若这次操作中没有n/2堆不为 ...
随机推荐
- 装了ubuntu之后,只能进入ubuntu系统,不能进入windows系统
电脑之前安装的是Windows 7系统, 后来在安装Linux系统中(快要完成)出现了故障, 没办法只能关机,之后重启,重启后只能进入Linux系统了 解决方案: 使用sudo update-grub ...
- mysql操作手册
开启日志:https://segmentfault.com/a/1190000003072237 常用词: Mysql:一种免费的跨平台的数据库系统 E:\mysql:表示是在dos 命令窗口下面 ...
- 两种最常用的 HTTP 方法:GET 和 POST。
什么是 HTTP? 超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信. HTTP 的工作方式是客户机与服务器之间的请求-应答协议. web 浏览器可能是客户端,而计算机上的网络应用程 ...
- H5+ 重写在线升级版本比较代码
重写h5+在线升级版本比较代码 hello h5+版本在线升级提供了如下的版本比较方法,逻辑比较繁琐,相关判断多余,非常不宜读. 先判断新旧版本有无, 接着分割为数组比较数组项大小,而且还只取了前四项 ...
- 基于GIS的空间分析功能分析芝加哥小熊队和白袜队的球迷范围
将交换格式的文件转换为要素类 在ArcCatalog中新建地址定位器 设置地址定位器的样式 选择Arctoolbox->地理编码工具->对地址进行地理编码 定义坐标系 定义坐标系后如图所示 ...
- 洛谷P2504 [HAOI2006]聪明的猴子
#include<bits/stdc++.h> using namespace std; ; ; int n,m,k,ans; double Max; int monkey[maxn]; ...
- day3_python之函数参数
一.形参 在定义函数时,括号内的参数称为形参,特点:形参就是变量名 def foo(x, y): # x=1,y=2 print(x) print(y) 二.实参 在调用函数时,括号内的参数成为实参, ...
- 【codeforces 520A】Pangram
[题目链接]:http://codeforces.com/problemset/problem/520/A [题意] 给你一个字符串. 统计里面有没有出现所有的英文字母->'a'..'z' 每个 ...
- html选择题
1.下面关于css样式和html样式的不同之处说法正确的是(A) A.html样式只影响应用它的文本和使用所选html样式创建的文本 B.css样式只可以设置文字字体样式 不仅仅能够设置 ...
- oracle sum()聚合函数
原文链接:https://blog.csdn.net/cizatu5130/article/details/100291347 oracle sum()聚合函数 2016-05-13 20:08:00 ...