【原题在此】

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. bash手册 之重定向原理与实现

    http://www.gnu.org/software/bash/manual/bashref.html#Redirections http://www.cnblogs.com/weidagang20 ...

  2. python学习笔记--easy_install和pip

    "A tool for installing and managing Python packages"     --pip easy_insall和pip都提供了在线一键安装模块 ...

  3. spring使用aop

    基于spring-framework-4.1.7使用aop >>>>>>>>>>>>>>>>>&g ...

  4. mysql left用法

    LEFT(str,len) 返回字符串str的最左面len个字符. SELECT LEFT('123456789',5)

  5. Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合

    项目环境背景: 操作系统:win7 JDK:1.7 相关依赖包,截图如下:

  6. [GDI+] 生成缩略图的类文件SmallImage (转载)

    直接看代码吧,大家可以直接复制使用 /// <summary> /// 类说明:SmallImage类, /// 编码日期:2012-08-20 /// 编 码 人: 苏飞 /// 联系方 ...

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

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

  8. SSH整合笔记

    SSH:spring+struts+hibernate. 一:所需jar: 需要注意的是: hibernate+spring需要Spring-orm-xxx.jar struts+spring需要st ...

  9. Java RMI 框架_远程方法调用(2016-08-16)

    概念: Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可 ...

  10. prime,素数的判断——c语言

    输入一个数a,求他是否是素数(用函数) 程序: #include<stdio.h> int prime(int a)-----------------------------------/ ...