POI2000 Stripes -------SG

Stripes

Time Limit:1000MSMemory Limit:30000KB
Total Submit:71Accepted: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 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

 

题目链接地址:http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1328

题意:其实就是给你L颗石子,你可以取连续的C颗石子,或者连续的Z颗石子,或者连续的N颗石子,谁不能取了,谁就输了,问甲乙两人谁有必胜策略。

其实这题就是SG的化身。

#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");
        }
    }
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值