POI 2000 ------Stripes

Stripes

Time Limit:1000MS Memory Limit:30000KB
Total Submit:94 Accepted:43

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 colour.

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

Players make their moves by turns. Move consists of laying a stripe of any colour 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 should contain m lines. Only one number should 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

 一排石子有L个,甲乙两人轮流从中取“紧紧挨着的”A或B或C枚石子。

谁不能取了,谁就是输家。已知A, B, C, L,问甲乙二人谁有必胜策略。

http://acm.cs.ecnu.edu.cn/problem.php?problemid=1328

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 using namespace std;
 6 
 7 bool use[1003];
 8 int  SG[1003];
 9 void prepare(int a,int b,int c)
10 {
11     int i,j,k;
12     SG[0]=0;
13     for(i=1;i<=1000;i++)
14     {
15         memset(use,false,sizeof(use));
16         for(j=1;j<=i-a+1;j++)
17         {
18             if(i-j-a+1>=0)
19             {
20             k=SG[j-1]^SG[i-j-a+1];
21             use[k]=true;
22             }
23         }
24         for(j=1;j<=i-b+1;j++)
25         {
26             if(i-j-b+1>=0)
27             {
28             k=SG[j-1]^SG[i-j-b+1];
29             use[k]=true;
30             }
31         }
32         for(j=1;j<=i-c+1;j++)
33         {
34             if(i-j-c+1>=0)
35             {
36             k=SG[j-1]^SG[i-j-c+1];
37             use[k]=true;
38             }
39         }
40         for(j=0;;j++)
41         if(use[j]==false)
42         {
43             SG[i]=j;
44             break;
45         }
46     }
47 }
48 
49 int main()
50 {
51     int a,b,c;
52     int m,x;
53     while(scanf("%d%d%d",&a,&b,&c)>0)
54     {
55         memset(SG,0,sizeof(SG));
56         prepare(a,b,c);
57         scanf("%d",&m);
58         while(m--)
59         {
60             scanf("%d",&x);
61             if(SG[x]==0)
62                 printf("2
");
63             else printf("1
");
64         }
65     }
66     return 0;
67 }
原文地址:https://www.cnblogs.com/tom987690183/p/3439172.html