POI2000 Stripes ------- SG

Source: Internet
Author: User

Stripes
Time Limit: 1000 MSMemory Limit: 30000KB
Total Submit: 71 Accepted: 31
Description

Stripes is a two player game. necessary requisites are a board and rectangular stripes in three colours: red, green and blue. all the red stripes have dimensions c x 1, green-z x 1, and blue-n x 1, where c, z and n are integers. players have at their disposal an unlimited pool of stripes of each color.

A game board is a rectangle of dimensions p x 1 and consists of p fields of size 1x1.

Players make their moves by turns. Move consists of laying a stripe of any color on the board. There are the following rules in force:

A stripe cannot stick out of the board,
The covering (even partially) the earlier laid stripes is forbidden.
The ends of a stripe have to adhere to the edges of the fields on the board. The player, who is not able to perform his move in accordance to the game rules first, loses.
The first player is this one, who makes the first move in the game. it is said, that the first player has a winning strategy, if independently of the moves of the second player he can always win.

Task
Write a program, which:

1. reads sizes of stripes and of at least one board
2. for each board determines, whether the first player has a winning strategy,
3. writes the results.
Input

The first line of the input consists of three integers c, z and n, 1 <= c, z, n <= 1000, equal to the lengths of stripes, adequately: red, green and blue ones. numbers in the line are separated by single spaces.

The second line of the file PAS. IN consists of one number m, 1 <= m <= 1000, which is equal to the number of different boards to consider. lines from the 3-rd to the (m + 2)-th consists of one number p, 1 <= p <1000. number in the (I + 2)-th line is the length of the I-th board.

Output

The output shoshould contain m lines. Only one number shoshould be written in the I-th line of the file:

1-if the first player has a winning strategy on the I-th board
2-otherwise.
Sample Input

1 5 1
3
1
5
6
Sample Output

1
1
2
Source
POI 2000 I Stage
 
Question link address: http://www.acm.cs.ecnu.edu.cn/problem.php? Problemid = 1328
In fact, it is just to give you 1 stone. You can take C stones in a row, Z stones in a row, or N stones in a row. No one can take them anymore, if you lose, you can ask both parties who have a winning strategy.
In fact, this is the embodiment of SG.
[Cpp]
# Include <iostream>
# Include <cstdlib>
# Include <stdio. h>
# Include <memory. h>
Using namespace std;
Int color [3];
Int dp [1010];
Void init ()
{
For (int I = 0; I <= 1000; I ++)
{
Bool g [1010] = {0 };
For (int j = 0; j <3; j ++)
For (int k = color [j]; k <= I; k ++)
{
Int t = dp [k-color [j] ^ dp [I-k];
G [t] = 1;
}
For (int j = 0; j <= 1000; j ++)
If (! G [j])
{Dp [I] = j; break ;}
}
 
}
Int main ()
{
While (scanf ("% d", & color [0])! = EOF)
{
For (int I = 1; I <3; I ++)
Scanf ("% d", & color [I]);
Memset (dp, 0, sizeof (dp ));
Init ();
Int t;
Scanf ("% d", & t );
While (t --)
{
Int n;
Scanf ("% d", & n );
If (dp [n] = 0) puts ("2 ");
Else puts ("1 ");
}
}
}


Author: qiqijianglu

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.