UVALive 3668 A Funny Stone Game
题目链接:UVALive - 3668
题目大意为给定n堆石子,每次的操作是选择三个数i<j<=k,从i中拿一枚石子,在j和k中分别放入一枚石子。不能操作者输。求先手是否能赢,若可以,则输出字典序最小的第一步操作。
思路是把在每个位置上的每颗石子当成一个游戏。
用SG[i]表示在第i堆中的一颗石子的sg函数。
则SG[i]=mex(SG[j] ^ SG[k])。
然后异或求游戏的和即可。
为找到字典序最小的第一步操作,我们枚举第一步操作,然后求游戏的和即可。
代码如下:
#include"cstdio"
#include"iostream"
#include"cstring"
#include"algorithm"
#include"cstdlib"
#include"vector"
#include"set"
#include"map"
#include"cmath"
using namespace std;
typedef long long LL;
const LL MAXN=; int n;
int f[MAXN];
int sg(int x)
{
if(x==n) return ;
if(f[x]!=-) return f[x];
int vis[];
memset(vis,,sizeof(vis));
for(int i=x+;i<=n;i++)
for(int j=i;j<=n;j++)
vis[sg(i)^sg(j)]=;
for(int i=;i<;i++)
if(!vis[i])
return f[x]=i;
return ;
}
int d[MAXN];
int cal()
{
memset(f,-,sizeof(f));
int ans=;
for(int i=;i<=n;i++)
if(d[i]%!=)
ans ^= sg(i);
return ans;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int t=;
while(scanf("%d",&n)!=EOF && n)
{
for(int i=;i<=n;i++)
scanf("%d",&d[i]);
int i,j,k;
bool ok=false;
for(i=;!ok && i<=n;i++)
for(j=i+;!ok && j<=n;j++)
for(k=j;!ok && k<=n;k++)
if(d[i]>)
{
d[i]--;
d[j]++;
d[k]++;
if(cal()==)
ok=true;
d[i]++;
d[j]--;
d[k]--;
}
printf("Game %d: ",++t);
if(ok) printf("%d %d %d\n",i-,j-,k-);
else printf("-1 -1 -1\n");
}
return ;
}
UVALive 3668 A Funny Stone Game的更多相关文章
- UVALive 3668 A Funny Stone Game(博弈)
Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- UVALive 5059 C - Playing With Stones 博弈论Sg函数
C - Playing With Stones Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu S ...
- POJ1740A New Stone Game[组合游戏]
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5769 Accepted: 3158 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- timus 1180. Stone Game 解题报告
1.题目: 1180. Stone Game Time limit: 1.0 secondMemory limit: 64 MB Two Nikifors play a funny game. The ...
- HDU 4048 Zhuge Liang's Stone Sentinel Maze
Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/327 ...
随机推荐
- SWERC2015-I Text Processor
题意 给一个长度为\(n\)的字符串\(s\),再给定一个\(w\),问对于所有的\(i\in [1,n-w+1]\),\(s[i..i+w-1]\)有多少个不同字串.\(n,w\le 10^5\). ...
- 【BZOJ1494】【NOI2007】生成树计数(动态规划,矩阵快速幂)
[BZOJ1494][NOI2007]生成树计数(动态规划,矩阵快速幂) 题面 Description 最近,小栋在无向连通图的生成树个数计算方面有了惊人的进展,他发现: ·n个结点的环的生成树个数为 ...
- max os取消开机启动
原文:http://liuzhichao.com/p/1667.html 安装MAMP后,启动服务时提示Apache启动失败,80端口被占用.查看进程发现存在几个httpd. OS X自带Apache ...
- 【bzoj2759】一个动态树好题
Portal -->bzoj2759 Solution 哇我感觉这题真的qwq是很好的一题呀qwq 很神qwq反正我真的是自己想怎么想都想不到就是了qwq 首先先考虑一下简化版的问题应该怎么解决 ...
- 【单调队列】【P3957】 跳房子
传送门 Description 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 $n$ 个格子,这些格子都 ...
- Java之基础20160806
注意这里介绍的JAVA基础是指你对C语言已经比较熟练或者有一定基础了,再学习如下这知识就会比较快. 1.JAVA也是从MAIN开始执行,但是要先定义类,文件名要与类名一致并且类名首字母要大写,同时JA ...
- db2 数据库操作JDBC .addBatch() 方法执行时,报错排查结果
今天调试db2数据的存储时,jdbc使用addBatch方法时,抛出异常,异常信息如下: [jcc][1091][10404][3.62.56] 数据转换无效:参数实例 对于所请求的转换无效. ER ...
- jquery、css3动态显示百分比圆
动态显示百分圆 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <m ...
- kotlin Hello World 以及关键字
hello world:(支持函数式编程,不需要放到 class 中) fun main(args: Array<String>) { println("Hello World& ...
- P1967 货车运输 树链剖分
题目描述 AA国有nn座城市,编号从 11到nn,城市之间有 mm 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 qq 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重的情况下,最 ...