1378 - A Funny Stone Game

Time limit: 3.000 seconds

The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., n - 1. Two persons pick stones in turn. In every turn, each person selects three piles of stones numbered ijk (i < jj k and at least one stone left in pile i). Then, the person gets one stone out of pile i, and put one stone into pile j and pile k respectively. (Note: if j = k, it will be the same as putting two stones into pilej). One will fail if he can't pick stones according to the rule.

David is the player who first picks stones and he hopes to win the game. Can you write a program to help him?

The number of piles, n, does not exceed 23. The number of stones in each pile does not exceed 1000. Suppose the opponent player is very smart and he will follow the optimized strategy to pick stones.

Input

Input contains several cases. Each case has two lines. The first line contains a positive integer n ( 1  n 23) indicating the number of piles of stones. The second line contains n non-negative integers separated by blanks, S0,...Sn-1 ( 0  Si  1000), indicating the number of stones in pile 0 to pile n - 1respectively.

The last case is followed by a line containing a zero.

Output

For each case, output a line in the format ``Game ti j k". t is the case number. ij and k indicates which three piles David shall select at the first step if he wants to win. If there are multiple groups of ijand k, output the group with the minimized lexicographic order. If there are no strategies to win the game,ij and k are equal to -1.

Sample Input

4
1 0 1 100
3
1 0 5
2
2 1
0

Sample Output

Game 1: 0 2 3
Game 2: 0 1 1
Game 3: -1 -1 -1 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4124
题意:略。
思路:分解的方法,《解析一类组合游戏》中的第一题。几句话看了几个小时,这个伤不起。
   后来想到了,相同局面的化简,顿时明白了这种分解的方法。
子局面,和下一个局面。
堪称经典题。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; int SG[];
bool use[];
void prepare()
{
int i,j,s;
SG[]=;
for(i=;i<=;i++)
{
memset(use,false,sizeof(use));
for(j=;j<i;j++)
for(s=;s<i;s++)
{
use[ SG[j]^SG[s] ]=true;
}
for(j=;;j++)
if(use[j]==false)
{
SG[i]=j;
break;
}
}
}
int main()
{
int n,i,j,ans,s,T=;
int f[];
bool flag;
prepare();
while(scanf("%d",&n)>)
{
if(n==)break;
for(i= ,ans=;i<n;i++)
{
scanf("%d",&f[i]);
if(f[i]&)
{
ans=ans^SG[n-i];
}
}
printf("Game %d: ",++T);
if(ans==)
{
printf("-1 -1 -1\n");
continue;
}
flag=false;
for(i=;i<n;i++)
{
if(flag==true) break;
if(f[i]==)continue;
for(j=i+;j<n;j++)
{
if(flag==true) break;
if(f[j]==)continue;
for(s=i+;s<n;s++)
{
if(f[s]==)continue;
if( (SG[n-i]^SG[n-j]^SG[n-s])== ans)
{
printf("%d %d %d\n",i,j,s);
flag=true;
break;
}
}
}
} }
return ;
}

Uva 1378 - A Funny Stone Game的更多相关文章

  1. uva 1378 - A Funny Stone Game(组合游戏)

    题目链接:uva 1378 - A Funny Stone Game 题目大意:两个人玩游戏,对于一个序列,轮流操作.每次选中序列中的i,j,k三个位置要求i<j≤k,然后arr[i]减1,对应 ...

  2. UVa 1378 A Funny Stone Game [博弈论 SG函数]

    A Funny Stone Game 题意: $n \le 23$堆石子,每次选择$i < j \le k$,从$i$拿走1颗$j,k$各放入一颗,不能取就失败.求先手是否必胜以及第一次取的策略 ...

  3. uva 1378 A Funny Stone Game (博弈-SG)

    题目链接:http://vjudge.net/problem/viewProblem.action?id=41555 把第i堆的每个石子看出一堆个数为n-i的石子,转换为组合游戏 #include & ...

  4. uva 1378 - A Funny Stone Game sg博弈

    题意:David 玩一个石子游戏. 游戏中,有n堆石子,被编号为0..n-1.两名玩家轮流取石子. 每一轮游戏.每名玩家选取3堆石子i,j,k(i<j,j<=k,且至少有一枚石子在第i堆石 ...

  5. uva 1567 - A simple stone game(K倍动态减法游戏)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=4342">题目链接:uva 1567 - ...

  6. 最小瓶颈路 Uva 534 Frogger

    说明:关于Uva的题目,可以在vjudge上做的,不用到Uva(那个极其慢的)网站去做. 最小瓶颈路:找u到v的一条路径满足最大边权值尽量小 先求最小生成树,然后u到v的路径在树上是唯一的,答案就是这 ...

  7. 10165 - Stone Game(Nim游戏)

    UVA 10165 - Stone Game 题目链接 题意:给定n堆石子,每次能在一堆取1到多个.取到最后一个赢,问谁赢 思路:就裸的的Nim游戏,利用定理求解 代码: #include <s ...

  8. 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 ...

  9. POJ 2235 Frogger / UVA 534 Frogger /ZOJ 1942 Frogger(图论,最短路径)

    POJ 2235 Frogger / UVA 534 Frogger /ZOJ 1942 Frogger(图论,最短路径) Description Freddy Frog is sitting on ...

随机推荐

  1. codis__通用的使用模式

    1,按功能模块分成不同的productName 参照 sample_user, sample_dynamic (见附件) sample_user.tar.gz,sample_dynamic.tar.g ...

  2. 基础篇:3.4)3d模型绘制的好坏会影响产品合格率(注意点)

    本章目的:为了量产品的产能与合格率,重视3d图纸. 1.前言 作者希望本文能引起重视,是那些刚入行业的菜鸟: 还有只用2d图纸,便能绘制出能量产合格品的前辈大牛工程师. 2.3d图纸不合格的现状及典型 ...

  3. Pycharm快捷键配置

    1.主题 毫无疑问Pycharm是一个具有强大快捷键系统的IDE,这就意味着你在Pycharm中的任何操作,例如打开一个文件.切换编辑区域等,都可以通过快捷键来实现.使用快捷键不仅能提高操作速度,看起 ...

  4. 128th LeetCode Weekly Contest Capacity To Ship Packages Within D Days

    A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...

  5. 让windows登陆界面显示administrator账户

    如果windowsXP只有一个administrator账户,在开机登陆windows的欢迎界面,会出现这个账户名,点击,输入密码就可登陆到windows桌面: 如果新建了另一个管理员账户,在欢迎界面 ...

  6. TP5.1 查看具体版本

    https://blog.csdn.net/haibo0668/article/details/80865785 echo \think\facade\App::version(); composer ...

  7. [转] Citrix XenDesktop桌面登录VM提示Citrix Web插件错误

    [From] http://blog.51cto.com/xuhaili100love/1223707 [适用版本] 适用所有Citrix虚拟桌面版本 [现象描述] 使用SC登录虚拟机提示“无法访问您 ...

  8. 1.使用frp穿透内网

    1.前因后果 1.1弃用ngrok 为节约服务器成本,花了500多块买了一个华为云得1G 1核心 5M得云服务器.然后用ngrok来穿透内网.一直用得还  但是今天在弄nginx得时候发现 ngrok ...

  9. oracle mysql的序列的新增、删除、修改及使用

    序列的使用  参考文献: https://blog.csdn.net/meijory/article/details/51891529 1.序列介绍 序列: 是 oracle 提供的用于产生一系列唯一 ...

  10. Linux-文件目录类命令

    l 文件目录类 pwd 指令 基本语法 pwd (功能描述:显示当前工作目录的绝对路径) 应用实例 案例:显示当前工作目录的绝对路径 ls指令 基本语法 ls [选项] [目录或是文件] 常用选项 - ...