【原题在此】

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. Visual Studio 调试技巧 (三) -- 调试第三方组件代码

    上次我们提到,没有源代码而且没有调试符号,我们也可以 Debug.有人可能会问,我什么时候需要在这种情况下调试吗?! 是的.比方说,我们用了某些第三方的组件,这些组件里面难免也会有 Bug.就算是微软 ...

  2. 用Markdown优雅的渲染我们的网页

    认识 Markdown Markdown 是一种用来写作的轻量级「标记语言」,它用简洁的语法代替排版,而不像一般我们用的字处理软件 Word 或 Pages 有大量的排版.字体设置.它使我们专心于码字 ...

  3. (转)网站隔几天打不开,多次重启Apache解决办法

    网站打不开了重启一下apache又好了,但过二天又打不开了,只有重启一下才好,基本上二天重起一次,本文主要解决这个问题 工具/原料 linux服务器 网站 方法/步骤   注意观察cpu占用情况{:s ...

  4. 浅谈C#关于AOP编程的学习总结

    难得在这样一个节日里给写出一篇博客,却没有佳人相约,没办法,这就是一个程(dan)序(shen)猿(gou)的真实生活情景,每天除了coding还是coding.唉..污染各位看官的眼了.好吧,进入正 ...

  5. 在fragment中调用SharedPreferences

    [o] Activity中调用SharedPreferences的方式: String prefsName = "mysetting"; SharedPreferences pre ...

  6. sql server split函数

    --创建分割函数CREATE FUNCTION dbo.Split(@String varchar(8000),@Delimiter char(1))returns @temptable TABLE ...

  7. cas系列(三)--HTTP和HTTPS、SSL

    (这段时间打算做单点登录,因此研究了一些cas资料并作为一个系列记录下来,一来可能会帮助一些人,二来对我自己所学知识也是一个巩固.) 本文转自異次元藍客点击打开链接 1.  HTTPS HTTPS(全 ...

  8. CI笔记6 json 传值

    CI3.x 使用json,配合easyui, 其实很简单,走了很多的弯路, 首先在ci的控制器重,建立2个方法,一个用于显示加载view,一个用于echo json,就可以了. 需要注意的是,在ci的 ...

  9. C# 静态类和非静态类的区别

    静态类和非静态类的区别 静态类: static       关键字 调用 类名.方法 在静态方法中只能访问静态成员  在静态类中只能有静态成员 在非静态类中 即可有非静态成员,也可以有静态成员 在静态 ...

  10. C# 匿名表达式(Lambda表达式)

    匿名表达式 这次来说说Lambda表达式吧,反正也简单,我也不像其他高手那样强调来强调去,只讲一下方法: 准备条件如下: 第一,匿名表达式必须存在与之对应的委托. 只要存在相对应的委托就可以了.接下来 ...