"Poi2003/2004 Stage I"

Source: Internet
Author: User

"The original question here"

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

In the case presented in the figure (M = 7), a player was 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 he 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 integers m and n (2 <= m <= 109, 1 <= n <= 106, n < m) separated b Y a single space. The second line contains n increasing Numbers-these is the numbers of squares the pawns is set on. Numbers in the line is 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

"topic translation"

On a strip with M lattice, numbered 1 to m from left to right. Some of the lattice above some pieces, a lattice can only put a pawn, the first m lattice did not put pieces. Two people take turns, each operation is to choose a piece to the right, put it to the right of its nearest space. The first person to put the pieces in the M lattice victory. Q. How many kinds of strategies do you have to win the first step?

, the current player can move 2 coins to 4, or 3 coins to 4, or 6 coins to 7.

"Input Format"

The first line enters M,n. The second row of n indicates the position of each coin, respectively.

"Output Format"

The number of strategies that guarantee the Forerunner's victory in a row.

Analysis:

Visual This problem I do not think of it, the original can be transformed into a ladder model, but also listen to the Scy speak to know ~ ~

  

(Transferred from: http://blog.sina.com.cn/s/blog_51cea4040100h0ab.html)

Feel Bo Master is very powerful, but also is Meng Meng da ~ ~ So this problem turned into our familiar ladder model.

Then I started to play the code, and after that I finished my heart:

&&¥¥%% #这题好坑好坑好坑啊, all kinds of situations have to take into account. After converting the problem into a ladder model, even-numbered pieces are not useless!! A great contribution to the scheme!! The even order can be swept down to the odd order of the increase!! There are all kinds of special sentences, all dizzy ~ (data big Direct no matter, good trouble ~ ~)

hehe ~

The code here, the data is too big to get tat:

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7 using namespacestd;8 #defineMAXN 100001009 Ten intA[MAXN],C[MAXN]; One BOOLB[MAXN]; A  - intMain () - { the     intM,n; -scanf"%d%d",&m,&n); -memset (b,0,sizeof(b)); -      for(intI=1; i<=n;i++) +     { -scanf"%d",&a[i]); +b[a[i]]=1; A     } at     if(b[m-1]==1) -     { -         inti; -         intsum=0; for(i=m-1; i>=1; i--)if(!b[i]) Break; -printf"%d\n", M-1-i); -     } in     Else -     { toMemset (c,0,sizeof(c)); +         intsum=0, St; -          for(st=m-2; b[st];st--); the          for(inti=st;i>=1; i--) *         { $             if(b[i]==0) sum++;Panax Notoginseng             Elsec[sum]++; -         } the         intans=0; +          for(intI=1; i<=sum;i+=2) ans^=C[i]; A         if(ans==0) printf ("0\n"); the         Else +         { -             intmx=0; $              for(intI=0;(1<<i) <=ans;i++) $                 if((1<<i) &ans) mx= (1<<i); -             intH=0; -              for(intI=1; i<=sum;i+=2)  the                 if(C[I]&AMP;MX) h++; -              for(intI=2; i<=sum;i+=2)Wuyi              if(((ans^c[i-1])-c[i-1]) >=0&&c[i]>= ((ans^c[i-1])-c[i-1])) h++; theprintf"%d\n", h); -         } Wu     } -     return 0; About}
[poi2003/2004 stage I]

2016-04-16 10:23:03

"Poi2003/2004 Stage I"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.