LIGHT OJ 1199 - Partitioning Game
![]() ![]() |
PDF (English) | problem=1199" style="color:rgb(79,107,114)">Statistics |
problem=1199" style="color:rgb(79,107,114)">Forum |
Time Limit: 4 second(s) | Memory Limit: 32 MB |
Alice and Bob are playing a strange game. The rules of the game are:
1. Initially there are n piles.
2. A pile is formed by some cells.
3. Alice starts the game and they alternate turns.
4. In each tern a player can pick any pile and divide it into two unequal piles.
5. If a player cannot do so, he/she loses the game.
Now you are given the number of cells in each of the piles, you have to find the winner of the game if both of them play optimally.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 100). The next line contains n integers, where the ith integer denotes the number of cells in the ith pile. You can assume that the number
of cells in each pile is between 1 and 10000.
Output
For each case, print the case number and 'Alice' or 'Bob' depending on the winner of the game.
Sample Input |
Output for Sample Input |
3 1 4 3 1 2 3 1 7 |
Case 1: Bob Case 2: Alice Case 3: Bob |
Explanation
In case 1, Alice has only 1 move, she divides the pile with 4 cells into two unequal piles, where one pile has 1 cell and the other pile has 3 cells. Now it's Bob's turn. Bob divides the pile with 3 cells into two piles, where one pile has 1 cell and another
pile has 2 cells. So, now there are three piles having cells 1, 1, 2. And Alice loses, since she doesn't have any moves now.
题目大意:
有n堆石子(1<=n<=100),每一堆分别有ai个石子(1<=ai<=10000),一次操作能够使一堆石子变成两堆数目不相等(注意是不相等)的石子,最后不能操作就算输,问先手赢还是后手赢。
解题思路:
就是一个SG函数,提到SG函数这个就是求一下 当前状态的下一个状态,又由于 这 n 堆石子是相互独立的,没有影响 所以说 能够开用SG函数,
依据SG定理,如果 当前堆中有 m块石子 那么他的下一状态就可能有 {1,m-1},{2,n-2},...,{(m-1)/2,m-(m-1)/2}(把每一种情况都想到
而且分析出来)。
然后分完的那些 a和b块石子又能够进行分,以此类推。那么SG(x) = mex{ SG(1)^SG(x-1), SG(2)^SG(x-2),...,
SG((x-1)/2)^SG(x-(x-1)/2) },
然后我们要求的就是 SG[a[0]]^SG[a[1]]^...^SG[a[n-1]],假设结果是0就是 后手赢,否则 先手赢
My Code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 10000+5;
int sg[MAXN];
int hash[MAXN];
void Get_sg()///模板
{
memset(sg, 0, sizeof(sg));
for(int i=1; i<MAXN; i++)
{
memset(hash, 0, sizeof(hash));
for(int j=1; j*2<i; j++)
{
hash[sg[j]^sg[i-j]] = 1;
}
int j;
for(j=0; j<MAXN; j++)
if(!hash[j])
break;
sg[i] = j;
}
}
int main()
{
Get_sg();
int T;
scanf("%d",&T);
for(int cas=1; cas<=T; cas++)
{
int m, sum = 0;
scanf("%d",&m);
for(int i=0; i<m; i++)
{
int x;
scanf("%d",&x);
sum ^= sg[x];
}
if(sum)
printf("Case %d: Alice\n",cas);
else
printf("Case %d: Bob\n",cas);
}
return 0;
}
LIGHT OJ 1199 - Partitioning Game的更多相关文章
- Light OJ 1199 - Partitioning Game (博弈sg函数)
D - Partitioning Game Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Light OJ 1199:Partitioning Game(SG函数模板)
Alice and Bob are playing a strange game. The rules of the game are: 1. Initially there are n p ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
随机推荐
- 获取sevlet response值
调用: PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8 ...
- SuperMap打包部署要点
折腾了一段时间,终于要发布一个版本了,但SuperMap程序怎么发布呢,需要些什么必要条件呢?本来想问问超图的技术人员的,但都没人理我,估计都去开大会去了. 下面是自己测试出来的结果,主要是根据Sup ...
- ZH奶酪:PHP 使用DOMDocument抓取网页
原文链接:http://blog.csdn.net/xyzhaopeng/article/details/6626340 从一个HTML页面的一个表格中提取数据并且将这个数据整理出来加入到MySQL数 ...
- eclipse 远程调试程序
最近遇到一个非常恶心的问题,本地调试没有问题,到了线上就复发,逼于无奈只能使用eclipse远程调试,下面把步骤记录一下: 1.修改服务器的启动脚本,添加如下内容: export JPDA_ADDRE ...
- Spring MVC 中急速集成 Shiro 实践
相信有很多的程序员,不愿意进行用户管理这块代码实现. 原因之一,不同的JavaEE 系统,用户管理都会有个性化的实现,逻辑很繁琐. 而且是系统门面,以后背锅的几率非常大,可谓是低收益高风险. 最近在系 ...
- Response的返回内容类型
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6682514.html 服务器在返回结果给浏览器时,通常需要先设置响应头的contentType属性.那么,c ...
- yii框架的部署方法
yii框架(yii framework)的部署方法 刚開始学习的人来说,部署yii框架还是有一定难度的,Yii是一个基于组件.用于开发大型 Web 应用的高性能 PHP 框架.Yii提供了今日Web ...
- Publish to a Linux Production Environment
Publish to a Linux Production Environment By Sourabh Shirhatti In this guide, we will cover setting ...
- vmware安装找不到虚拟网卡解决方案
前一段实际,win7升级到win10发现vmware12没有虚拟网卡vnet1/vnet8.这不坑爹吗,没网卡能通信吗? 在网上搜寻一下发现可以重置网络,即可再次安装虚拟网卡...算是对问题的记录学习 ...
- Ubuntu18.04使用f3probe检测U盘实际容量
项目主页 https://fight-flash-fraud.readthedocs.io/ 使用f3probe 能快速检测出被测U盘的实际容量, 命令 $ sudo f3probe --destru ...