【原题在此】

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. Reactor构架模式--转载

    原文:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece76310468a3b404380143c86964868d4e419ce3b464 ...

  2. Struts工作流程

    Java Web 都是使用线程来处理用户的请求(request)的,一次请求对应一个处理线程.Struts 2会为每个处理线程分配一个Action对象, 将提交的参数注射到Action属性中,并调用A ...

  3. android开发之PreferenceScreen使用详解

    是在惭愧,学习android也有一段时间了,今天才是第一次接触PreferenceScreen.记录下来,与大家分享. 本文参考:http://lovezhou.iteye.com/blog/1020 ...

  4. RedHat7搭建MongoDB集群

    下载RPM安装包# wget -c -r -N -np -nd -L -nH https://repo.mongodb.org/yum/redhat/7/mongodb-org/stable/x86_ ...

  5. ThinkPHP的数据库访问的简单操作

    传统的sql与ThinkPHP中的sql相比较   以user表为例 $user=M('user'); 1: SELECT * FROM user----------$user->select( ...

  6. Nico Game Studio 1.基本UI和地图编辑基础功能

    完成了基本界面. 本来想自画UI,但是考虑到工作量较大和美观程度有限,以及工具使用对象是比较初级玩家,处于性价比和最初目的,放弃了自绘.

  7. TCP的服务流程

    TCP协议提供的是可靠的.面向连接的传输控制协议,即在传输数据前要先建立逻辑连接,然后再传输数据,最后释放连接3个过程.TCP提供端到端.全双工通信:采用字节流方式,如果字节流太长,将其分段:提供紧急 ...

  8. 使用openrowset跨库查询

    --insert fj_studentinfo--select *--from--  openrowset('SQLOLEDB','localhost';'sa';'password',dbname. ...

  9. RESTful 架构风格概述

    http://blog.igevin.info/posts/restful-architecture-in-general/(非常好) http://blog.igevin.info/posts/re ...

  10. SQL SERVER while循环

    在SQL数据库中,可以通过WHILE实现循环,下面就将为您介绍SQL循环执行while控制,希望对您提升WHILE的使用水平能够有些帮助. WHILE Boolean_expression    { ...