[POI2009]KAM-Pebbles
题目描述
Johny and Margaret are playing "pebbles".
Initially there is a certain number of pebbles on a table, grouped in n piles.
The piles are next to each other, forming a single row.
The arrangement of stones satisfies an additional property that each pile consists of at least as many pebbles as the one to the left (with the obvious exception of the leftmost pile).
The players alternately remove any number of pebbles from a single pile of their choice.
They have to take care, though, not to make any pile smaller than the one left to it.
In other words, the piles have to satisfy the initial property after the move as well.
When one of the players cannot make a move (i.e. before his move there are no more pebbles on the table), he loses.
Johny always starts, to compensate for Margaret's mastery in this game.
In fact Margaret is so good that she always makes the best move, and wins the game whenever she has a chance.
Therefore Johny asks your help - he would like to know if he stands a chance of beating Margaret with a particular initial arrangement.
Write a programme that determines answers to Johny's inquiries.
有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数。两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏。问先手是否必胜。
输入输出格式
输入格式:
In the first line of the standard input there is a single integer u (1<=u<=10) denoting the number of initial pebble arrangements to analyse.
The following 2u lines contain descriptions of these arrangements; each one takes exactly two lines.
The first line of each description contains a single integer n,1<=n<=1000 - the number of piles.
The second line of description holds non-negative integers separated by single spaces and denoting the numbers of pebbles in successive piles, left to right.
These numbers satisfy the following inequality a1<=a2...<=an.
The total number of pebbles in any arrangement does not exceed 1000.
多组输入,第一行一个整数u代表数据组数(1<=u<=10)
接下来共2*u行,每两行代表一组数据:
第一行只有一个整数n(1<=n<=1000),表示石子堆数;
第二行有n个整数用空格隔开,第i个整数ai表示第i堆的石子个数,保证a1<=a2<=a3...<=an。
对于每组数据,保证石子总数不超过10000。
输出格式:
Precisely
lines should be printed out on the standard output.
The
-th of these lines (for
) should hold the word TAK (yes in Polish), if Johny can win starting with the
-th initial arrangement given in the input, or the word NIE (no in Polish), if Johny is bound to lose that game, assuming optimal play of Margaret.
输出u行,如果第i组数据先手必胜,输出“TAK”,否则输出“NIE”。
输入输出样例
2
2
2 2
3
1 2 4
NIE
TAK
设c[i]为可以取得石子数,显然c[i]=a[i]-a[i-1]
当取了x个时,c[i]-=x,c[i+1]+=x
相当于i给x给i+1
可以看做石子数为c[i],做反向阶梯博弈
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a[],ans,n;
int main()
{int T,i;
cin>>T;
while (T--)
{
cin>>n;
ans=;
for (i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for (i=n;i>=;i-=)
ans^=(a[i]-a[i-]);
if (ans) cout<<"TAK"<<endl;
else cout<<"NIE"<<endl;
}
}
[POI2009]KAM-Pebbles的更多相关文章
- BZOJ 1115: [POI2009]石子游戏Kam
1115: [POI2009]石子游戏Kam Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 883 Solved: 545[Submit][Stat ...
- 【BZOJ】【1115】【POI2009】石子游戏KAM
博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...
- bzoj 1115: [POI2009]石子游戏Kam -- 博弈论
1115: [POI2009]石子游戏Kam Time Limit: 10 Sec Memory Limit: 162 MB Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前 ...
- 【BZOJ1115】[POI2009]石子游戏Kam 阶梯博弈
[BZOJ1115][POI2009]石子游戏Kam Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要 ...
- 【BZOJ】1115: [POI2009]石子游戏Kam
http://www.lydsy.com/JudgeOnline/problem.php?id=1115 题意:n堆石子,个数是从左到右单增.每一次可以从任意堆取出任意石子,但要保持单增这个性质.问先 ...
- [BZOJ 1115] [POI2009] 石子游戏Kam 【阶梯博弈】
题目链接:BZOJ - 1115 题目分析 首先看一下阶梯博弈: 阶梯博弈是指:初始有 n 堆石子,每次可以从任意的第 i 堆拿若干石子放到第 i - 1 堆.最终不能操作的人失败. 解法:将奇数位的 ...
- bzoj1115: [POI2009]石子游戏Kam
Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏 ...
- BZOJ1115:[POI2009]石子游戏Kam(博弈论)
挺水的 听说是阶梯nim和,就去看了一下,然后就会了= = 观察题目,发现拿第i堆棋子k个造成的影响就是第i+1堆棋子能多拿k个 可以把模型转化为,有n堆石子,每次从某一堆拿一个石子,放在下一堆中,不 ...
- BZOJ 1115: [POI2009]石子游戏Kam [阶梯NIM]
传送门 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏.问先手是否必胜 ...
- BZOJ.1115.[POI2009]石子游戏Kam(阶梯博弈)
BZOJ 洛谷 \(Description\) 有\(n\)堆石子.除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作,每次可以从一堆石子中拿掉任意多的石子,但要保证操作后仍然满足初始时 ...
随机推荐
- CountDownLatch 源码解析—— await()
上一篇文章说了一下CountDownLatch的使用方法.这篇文章就从源码层面说一下await() 的原理. 我们已经知道await 能够让当前线程处于阻塞状态,直到锁存器计数为零(或者线程中断). ...
- 用C语言实现QQ刷屏
我在百度传课上录制了一个用C语言实现刷屏的视频,有兴趣的可以移步这边:https://chuanke.baidu.com/6658388-238008.html
- 20162330 第10周 MySort实验
关于MySort的进一步实践 课堂作业题目如下: 模拟实现Linux下Sort -t : -k 2的功能.参考Sort的实现.提交码云链接和代码运行截图. import java.util.*; pu ...
- 算法——算法时间复杂度的计算和大O阶的推导
在算法分析中,我们将语句总的执行次数记为T(n)进而分析T(n)随n的变化情况确认T(n)的数量级.一般情况下,T(n)随n增大变化最缓慢的算法为最优算法. 根据定义,T(n)的求法是很简单的,也就是 ...
- org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be res
解决:web项目出现如上问题,据查是版本问题: JSTL 1.0 的声明是: <%@ taglib prefix="c" uri="http://java.sun. ...
- django 连接mysql
环境 Linux 修改工程目录下的settings.py 文件 #!!!!!!!!切勿出现中文 即便//注释也不行 DATABASES = { 'default': { 'ENGINE': 'djan ...
- iOS Storyboard unwind segues使用小结
使用storyboard开发的时候,经常会在一个scene上添加一个button,再拖拽这个button到某个想要关联的页面,最后选择push的方式跳转.这样scene_A和scene_B就有了一个& ...
- 数据故障的恢复-MSSQL ndf文件大小变为0 KB恢复过程
一.故障描述 成都某客户,存储损坏,数据库崩溃.重组存储,恢复数据库文件,发现有四个ndf文件大小变为0 KB.数据库大小约80TB.数据库中有1223个文件,数据库每10天生成一个NDF文件,每个N ...
- CISCO路由器练习
前言: 总结了昨天的学习和今天的单臂路由 写了今天的文章. 目录: 路由器的基本配置 单臂路由的练习 正文: 路由器基本配置 环境要求 cisco模拟器 2台交换机 2台PC 1台路由器 路由器介绍: ...
- 使用 VSCode 编写 .NET Core 项目之初体验
注:本文在根据 微软官方文档指导下,根据自己的学习中整理,并不完全照搬文档,但也大体和文档学习路线相似,主要为记录学习过程. 官方学习地址: https://code.visualstudio.com ...