博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POI2009]KAM-Pebbles
阅读量:5232 次
发布时间:2019-06-14

本文共 3068 字,大约阅读时间需要 10 分钟。

题目描述

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: 
222 231 2 4
输出样例#1: 
NIETAK 设c[i]为可以取得石子数,显然c[i]=a[i]-a[i-1] 当取了x个时,c[i]-=x,c[i+1]+=x 相当于i给x给i+1 可以看做石子数为c[i],做反向阶梯博弈
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int a[10001],ans,n; 8 int main() 9 {
int T,i;10 cin>>T;11 while (T--)12 {13 cin>>n;14 ans=0;15 for (i=1;i<=n;i++)16 {17 scanf("%d",&a[i]);18 }19 for (i=n;i>=1;i-=2)20 ans^=(a[i]-a[i-1]);21 if (ans) cout<<"TAK"<

 

转载于:https://www.cnblogs.com/Y-E-T-I/p/8641500.html

你可能感兴趣的文章
python 读 xlsx
查看>>
设计模式C#合集--工厂方法模式
查看>>
IDEA中Git之项目场景
查看>>
java
查看>>
题目1104:整除问题
查看>>
Facebook----扎克伯格
查看>>
mac下破解apk文件以及apktool的相关使用
查看>>
优化网站设计(二十六):设计“智能”的事件处理程序
查看>>
性能测试总结(一)---基础理论篇
查看>>
前端程序员容易忽视的一些基础知识
查看>>
【日常水题-bfs】求细胞数量
查看>>
【noip系列——模拟】 Vigenère 密码
查看>>
windows下一台机器运行多个tomcat
查看>>
flask flask参数 app 配置
查看>>
安装SQL Server提示“等待数据库引擎恢复句柄失败”
查看>>
【转载】分贝是个什么东西?
查看>>
2015 10月19日 工作计划与执行
查看>>
20145206邹京儒Exp6 信息搜集与漏洞扫描
查看>>
【Cocos2d-x for WP8 学习整理】(3)CCScrollView 实现捕鱼达人一样的场景选择界面...
查看>>
python之random模块
查看>>