【原题在此】

Let us consider a game on a rectangular board m x 1 consisting of m elementary squares numbered successively from 1 to m. There are n pawns on the board, each on a distinct square. None of them occupies the square with number m. Each single move in the is the following action: the moving player picks a pawn from any occupied square chosen at will and places it on the first unoccupied square with a larger number. The two players make moves in turn. The one who puts a pawn on the last square, i.e. the square with a number m, wins.

In the case presented in the figure (m = 7), a player is allowed to move a pawn from square no. 2 to 4, from square no. 3 to 4 or from square no. 6 to 7. The latter ends the game.

We say a player's move is winning if after making it he can win the game, no matter what moves his opponent makes.

Task
Write a programme that:

reads the size of a board and the initial setup of pawns from the standard input,
determines the number of distinct winning moves the starting player may choose in the given initial situation,
writes the result to the standard output.

Input
The first line of the input contains two integers m and n (2 <= m <= 109, 1 <= n <= 106, n < m) separated by a single space. The second line contains n increasing numbers - these are the numbers of squares the pawns are set on. Numbers in the line are separated by single spaces.

Output
The first and only output line should contain the number of distinct winning moves possible for the starting player in the given initial situation.

Example
For the following input data:

5 2
1 3

the correct answer is:

1

For the following input data:

5 2
2 3

the correct answer is:

0

【题目翻译】

在一个有M个格子的长条上,从左到右编号1到M。一些格子上方有一些棋子,一个格子只能放一个棋子,第M格没有放棋子。两个人轮流操作,每次操作是选择一枚棋子往右放,放在它右边距离它最近的一个空格里。最先把棋子放在第M格的人胜利。问先手必胜的第一步策略一共有多少种?

上图中,当前玩家可以将2中的硬币移动到4,或3中的硬币到4,或6中的硬币到7。

【输入格式】

第一行输入m,n 。第二行n个数分别表示每一枚硬币所在的位置。

【输出格式】

进一行,保证先行者胜利的策略数。

分析:

  目测这题我自己是想不出来的了,原来可以转化为阶梯模型,也是听了scy讲了才知道~~

  

(转自:http://blog.sina.com.cn/s/blog_51cea4040100h0ab.html)

  感觉博主很厉害很厉害,同时也是萌萌哒~~于是这题就转成了我们熟悉的阶梯模型了。

  然后我开始打代码,打完之后,我的内心:

  &&¥¥%%#这题好坑好坑好坑啊,各种情况都要考虑到才行。把这题转换成阶梯模型之后,偶数阶的棋子并不是没有用的!!对方案有巨大贡献啊!!可以把偶数阶的扫下去相当于奇数阶的增加了!!还有各种特判,都晕了~(数据大的直接不管了,好麻烦~~)

  呵呵~

代码在这里,数据大的过不了TAT:

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define Maxn 10000100 int a[Maxn],c[Maxn];
bool b[Maxn]; int main()
{
int m,n;
scanf("%d%d",&m,&n);
memset(b,,sizeof(b));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]]=;
}
if(b[m-]==)
{
int i;
int sum=;for(i=m-;i>=;i--) if(!b[i]) break;
printf("%d\n",m--i);
}
else
{
memset(c,,sizeof(c));
int sum=,st;
for(st=m-;b[st];st--);
for(int i=st;i>=;i--)
{
if(b[i]==) sum++;
else c[sum]++;
}
int ans=;
for(int i=;i<=sum;i+=) ans^=c[i];
if(ans==) printf("0\n");
else
{
int mx=;
for(int i=;(<<i)<=ans;i++)
if((<<i)&ans) mx=(<<i);
int h=;
for(int i=;i<=sum;i+=)
if(c[i]&mx) h++;
for(int i=;i<=sum;i+=)
if(((ans^c[i-])-c[i-])>=&&c[i]>=((ans^c[i-])-c[i-])) h++;
printf("%d\n",h);
}
}
return ;
}

[POI2003/2004 stage I ]

2016-04-16 10:23:03

【POI2003/2004 stage I】的更多相关文章

  1. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  2. 【原创分享·支付宝支付】HBuilder打包APP调用支付宝客户端支付

    前言 最近有点空余时间,所以,就研究了一下APP支付.前面很早就搞完APP的微信支付了,但是由于时间上和应用上的情况,支付宝一直没空去研究.然后等我空了的时候,发现支付宝居然升级了支付逻辑,虽然目前还 ...

  3. 西川善司【神秘海域(Uncharted)】的图形分析

          本文是为传播0月8日发售的[神秘海域 合集]魅力而短篇连载的第2回,这次主要集中在神秘海域系列的图形的技术方面.原文链接在 http://weekly.ascii.jp/elem/000/ ...

  4. 【动态规划】【二分】【最长上升子序列】Vijos P1028 魔族密码

    题目链接: https://vijos.org/p/1028 题目大意: 给N个字符串(N<=2000),求能组成词链的单词最多有几个. 如果在一个由一个词或多个词组成的表中,除了最后一个以外, ...

  5. 【市场调研与分析】Intel发力移动安全领域——By Me at 20140613

                                                    [市场调研与分析]Intel发力移动安全领域                               ...

  6. 🏆(不要错过!)【CI/CD技术专题】「Jenkins实战系列」(3)Jenkinsfile+DockerFile实现自动部署

    每日一句 没有人会因学问而成为智者.学问或许能由勤奋得来,而机智与智慧却有懒于天赋. 前提概要 Jenkins下用DockerFile自动部署Java项目,项目的部署放心推向容器化时代机制. 本节需要 ...

  7. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  8. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

  9. 【AutoMapper官方文档】DTO与Domin Model相互转换(上)

    写在前面 AutoMapper目录: [AutoMapper官方文档]DTO与Domin Model相互转换(上) [AutoMapper官方文档]DTO与Domin Model相互转换(中) [Au ...

随机推荐

  1. hadoop错误ERROR namenode.NameNode (NameNode.javamain(1657)) - Failed to start namenode java.net.BindException:Port in use:host1:50070

    解决方法: 1.通过lsof -i:50070(lsof可以通过yum install lsof安装)查看,发现是mysql被占用了 2.修改mysql端口 从/usr/share/mysql/my- ...

  2. Cocos2d-x中获取设备语言的方法

    1.cocos2dx获取设备语言的方法:CCApplication::sharedApplication()->getCurrentLanguage() 2.cocos2dx 2.1.4支持识别 ...

  3. Audit(查看审核/审计信息)

    2013需要到 网站集管理-网站集审核设置 中设置要开启的审核项,开启之后sharepoint才会记录信息,信息存储在contentDB的AuditData中: 去读审计信息的sharepoint代码 ...

  4. JavaScript 应用开发 #5:为完成的任务添加样式

    判断一下任务的状态,如果是完成的任务,可以在任务项目的上面,添加一个额外的 css 类,在这个 css 类里,可以去定义完成的任务的样式.比如,把文字的颜色变成浅友色,并且在文字上面添加一条删除线.这 ...

  5. Unexpected CFBundleExecutable Key

    昨天晚上打包上传的时候报错: ERROR ITMS-90535: "Unexpected CFBundleExecutable Key. The bundle at 'Payload/xxx ...

  6. 20、CSS

    CSS 层叠样式表(Cascading Style Sheets). 用于定义显示HTML样式. DIV和SPAN div是块级元素. span是行级元素. 将一些页面中的内容包裹起来统一设置样式. ...

  7. chrome跨域配置

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --use ...

  8. VS2010打不开VS2012 .NET MVC 工程,及打开后部分模块加载不正确的解决办法

    转自http://www.xuebuyuan.com/2042634.html 首先,如果sln打开不正确,用(notepad++)打开sln 比如 VS2010的前两行为: Microsoft Vi ...

  9. AndroidStudio字体主题样式分享

    最近慢慢在从eclipse往AndroidStudio习惯,但总觉得AS的默认字体颜色看的不舒服,便花了些时间将字体颜色样式改成了和原来类似的.以下是效果图. 这里是下载地址http://downlo ...

  10. java 反射 - 获取成员变量的值.

    通过反射,可以获取所有声明的成员变量(包括所有的),代码如下: package spt.test.src; public class Person { private String name = &q ...