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 ...
随机推荐
- bzoj5123 [Lydsy12月赛]线段树的匹配
题意: 线段树是这样一种数据结构:根节点表示区间 [1, n]:对于任意一个表示区间 [l, r] 的节点,若 l < r, 则取 mid = ⌊l+r/2⌋,该节点的左儿子为 [l, mid] ...
- 【bzoj4425】[Nwerc2015]Assigning Workstations分配工作站 贪心+堆
题目描述 佩内洛普是新建立的超级计算机的管理员中的一员. 她的工作是分配工作站给到这里来运行他们的计算研究任务的研究人员. 佩内洛普非常懒惰,不喜欢为到达的研究者们解锁机器. 她可以从在她的办公桌远程 ...
- 学习NAT时引出网关
网关(Gateway) 网关实质上是一个网络通向其他网络的IP地址 只有设置好网关的IP地址,TCP/IP协议才能实现不同网络之间的相互通信
- [AT2304] [agc010_c] Cleaning
题目链接 AtCoder:https://agc010.contest.atcoder.jp/tasks/agc010_c 洛谷:https://www.luogu.org/problemnew/sh ...
- 【BZOJ2806】Cheat(后缀自动机,二分答案,动态规划,单调队列)
[BZOJ2806]Cheat(后缀自动机,二分答案,动态规划,单调队列) 题面 BZOJ 洛谷 题解 很有趣的一道题啊 对于在所有的串上面进行匹配? 很明显的后缀自动机 所以先构建出广义后缀自动机 ...
- Linux(一)——认识Linux
一.Linux介绍 (安装的是Centos6.7) 1.Linux 系统是一套免费使用和自由传播的类 Unix 操作系统(主要用在服务器上),是一个基于 POSIX 和 UNIX 的多用户.多任务.支 ...
- [雅礼集训 2017 Day1]市场
link 试题分析 可以容易发现此题维护的是一个数据结构,支持区间加,区间除,区间查询最大值.其实就是在$\log$级复杂度内维护除法操作. 我们发现当除数很大或者此串序列大小差不多时,我们令$a_i ...
- opencv2 直方图之calchist函数使用(转)
OpenCV提供了calcHist函数来计算图像直方图. 其中C++的函数原型如下:void calcHist(const Mat* arrays, int narrays, const int* c ...
- vs下取得资源文件中的版本信息
在Windows Mobile和Wince(Windows Embedded CE)下开发的产品,有时候需要显示当前产品的版本信息.一般来说,版本信息是保存在资源文件里面的,例如下图: 为了保持一致, ...
- Codeforces 25.E Test
E. Test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...