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 ...
随机推荐
- BZOJ5016 Snoi2017一个简单的询问(莫队)
容易想到区间转化成前缀和.这样每个询问有了二维坐标,莫队即可. #include<iostream> #include<cstdio> #include<cmath> ...
- Django获取多个数据及文件上传
1. 选择性别: 1)更新login.html模板 2)views.py中获取客户端提交的数据 3)当选择性别为“男”后,后台得到了gender=1. 2.选择爱好,可以多选,所以后台会获得多个数据. ...
- Android开发性能优化总结(一)
安卓开发应用首先要讲究良好的用户体验,如果一款软件卡顿现象严重,不流畅,经常崩溃,那么将给用户带来极不良好的体验,从而损失用户. 在实际开发和学习中,我总结了一下关于安卓性能的优化,供大家参考交流. ...
- 【BZOJ3244】【NOI2013】树的计数(神仙题)
[BZOJ3244][NOI2013]树的计数(神仙题) 题面 BZOJ 这题有点假,\(bzoj\)上如果要交的话请输出\(ans-0.001,ans,ans+0.001\) 题解 数的形态和编号没 ...
- Linux (四)其他一些服务的实现
一.防火墙 防火墙根据配置文件/etc/sysconfig/iptables 来控制本机的“出.入”网络访问行为 其对行为的配置策略有四个策略表 1. 基础必备技能 查看防火墙状态 ...
- python基础----多态与多态性、super函数用法、继承原理
一.多态与多态性 ㈠多态: 多态指的是一类事物有多种形态, ...
- python基础----__next__和__iter__实现迭代器协议
#_*_coding:utf-8_*_ __author__ = 'Linhaifeng' class Foo: def __init__(self,x): self.x=x def __iter__ ...
- yii2框架-yii2局部关闭(开启)csrf的验证
(1)全局使用,我们直接在配置文件中设置enableCookieValidation为true request => [ 'enableCookieValidation' => true, ...
- Django 分页 以及自定义分页
Django提供了一个新的类来帮助你管理分页数据,这个类存放在django/core/paginator.py.它可以接收列表.元组或其它可迭代的对象. 基本语法 1 2 3 4 5 6 7 8 9 ...
- 使用uiautomator时遇到问题的处理方法
本帖持续更新中… 一.使用adb devices无法连接到模拟器 这种情况可能是因为服务挂了之类的原因,重启一下服务 adb kill-server //关闭adb服务 adb start-serve ...