题目描述

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”。

输入输出样例

输入样例#1: 复制

2
2
2 2
3
1 2 4
输出样例#1: 复制

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的更多相关文章

  1. BZOJ 1115: [POI2009]石子游戏Kam

    1115: [POI2009]石子游戏Kam Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 883  Solved: 545[Submit][Stat ...

  2. 【BZOJ】【1115】【POI2009】石子游戏KAM

    博弈论 这个题……一看就觉得很捉急啊= =肿么办? 灵光一现:差分一下~ 那么我们看一下差分以后,从第 i 堆中拿走 k 个石子变成了:a[i]-=k; a[i+1]+=k; 嗯这就转化成了阶梯博弈! ...

  3. bzoj 1115: [POI2009]石子游戏Kam -- 博弈论

    1115: [POI2009]石子游戏Kam Time Limit: 10 Sec  Memory Limit: 162 MB Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前 ...

  4. 【BZOJ1115】[POI2009]石子游戏Kam 阶梯博弈

    [BZOJ1115][POI2009]石子游戏Kam Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要 ...

  5. 【BZOJ】1115: [POI2009]石子游戏Kam

    http://www.lydsy.com/JudgeOnline/problem.php?id=1115 题意:n堆石子,个数是从左到右单增.每一次可以从任意堆取出任意石子,但要保持单增这个性质.问先 ...

  6. [BZOJ 1115] [POI2009] 石子游戏Kam 【阶梯博弈】

    题目链接:BZOJ - 1115 题目分析 首先看一下阶梯博弈: 阶梯博弈是指:初始有 n 堆石子,每次可以从任意的第 i 堆拿若干石子放到第 i - 1 堆.最终不能操作的人失败. 解法:将奇数位的 ...

  7. bzoj1115: [POI2009]石子游戏Kam

    Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏 ...

  8. BZOJ1115:[POI2009]石子游戏Kam (博弈论)

    挺水的 听说是阶梯nim和,就去看了一下,然后就会了= = 观察题目,发现拿第i堆棋子k个造成的影响就是第i+1堆棋子能多拿k个 可以把模型转化为,有n堆石子,每次从某一堆拿一个石子,放在下一堆中,不 ...

  9. BZOJ 1115: [POI2009]石子游戏Kam [阶梯NIM]

    传送门 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏.问先手是否必胜 ...

  10. BZOJ.1115.[POI2009]石子游戏Kam(阶梯博弈)

    BZOJ 洛谷 \(Description\) 有\(n\)堆石子.除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作,每次可以从一堆石子中拿掉任意多的石子,但要保证操作后仍然满足初始时 ...

随机推荐

  1. python 面向对象的程序设计

    一:什么是编程范式? 编程是程序员用特定的语法 + 数据结构 + 算法组成的代码来告诉计算机如何执行任务的过程. 如果把编程的过程比喻为练习武功,那么编程范式指的就是武林中的各种流派,而在编程的世界里 ...

  2. beta冲刺5

    昨天的问题: 登陆页面的整合重新制作 各主机版本更迭 我的社团显示功能修改调整 主页的头部替换掉 +修复帖子无法显示内容的问题 +试着将邮箱等判定用正则表达式进行实时判定. 今天的完成: 主要是线下进 ...

  3. c语言字符类型作业

    一.PTA实验作业 题目1:7-2 统计一行文本的单词个数 1. 本题PTA提交列表 2. 设计思路 1.定义整形变量i=0,count=0,flag. 2.定义数组str[999] 3.输入str[ ...

  4. 论C++的智能指针

    一.简介   参考这篇博客,并且根据<C++ Primer>中相关知识,我总结了C++关于智能指针方面的内容.   为了解决内存泄漏的问题,便出现了智能指针.STL提供的智能指针有:aut ...

  5. 团队作业6——展示博客(Alpha版本)

    Deadline: 2017-12-3  23:00PM,以博客发表日期为准   评分基准 按时交 - 有分,检查的项目包括后文的两个方面 团队成员介绍 Alpha阶段进展 团队合作,各成员分工 Be ...

  6. C语言——第一次作业

    **学习内容总结** 本周进行了算法的初步学习,用计算机的思维方式去思考问题,并学习了如何用传统程序框图表示算法. 相关内容: 1.算法是用来解决问题的方法与步骤. 2.计算机擅长重复,常用枚举的方法 ...

  7. Python split()方法

    Python split()方法 描述 Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串 语法 split()方法语法: str.sp ...

  8. nyoj 过河问题

    过河问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:5   描述 在漆黑的夜里,N位旅行者来到了一座狭窄而且没有护栏的桥边.如果不借助手电筒的话,大家是无论如何也不敢过桥去的 ...

  9. python 一篇搞定所有的异常处理

    一:什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在python无法正常处理程序时就会发生一个异常(异常是python对象,表示一个错误) 异常就是 ...

  10. c# gridview 新增行

    string[] newRow = {"long","d","b"}; Gridview.Rows.Insert(Gridview.Rows ...