HDU 3980 (SG 环变成链 之前的先手变成后手)

题意
两个人在一个由 n 个玻璃珠组成的一个圆环上玩涂色游戏,游戏的规则是:
1、每人一轮,每轮选择一个长度为 m 的连续的、没有涂过色的玻璃珠串涂色
2、不能涂色的那个人输掉游戏

Aekdycoin 先手

开始时候是一个环,第一个人涂色后就变成了链,这时候就可以使用尼姆博弈了。但是注意一点此时第二个人应该变成尼姆博弈中的先手了。

第一次涂色后 变成 abcdxyzk 先手

n < m 先手无法涂 后手胜

Sample Input
2
3 1 // n m
4 2

Sample Output
Case #1: aekdycoin
Case #2: abcdxyzk

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 using namespace std ;
 5
 6 int sg[1010];
 7 bool vis[1010];
 8 int m , n ; //每次取m个
 9 int mex(int n) //求N的SG值
10 {
11     if(sg[n] != -1)return sg[n];
12     if(n < m)return sg[n] = 0;
13     memset(vis,false,sizeof(vis));
14     for(int i = m;i <= n;i++)
15         vis[mex(i-m)^mex(n-i)] = true;
16     for(int i = 0;;i++)
17         if(vis[i] == false)
18         {
19             sg[n] = i;
20             break;
21         }
22     return sg[n];
23 }
24
25 int main ()
26 {
27     int T ;
28     scanf("%d" , &T) ;
29     int iCase = 0 ;
30     while(T--)
31     {
32         scanf("%d%d",&n,&m);
33         iCase++;
34         if(n < m)  //只有n个 但是要涂m个  先手无法涂m个  先手败
35         {
36             printf("Case #%d: abcdxyzk\n",iCase);
37             continue;
38         }
39         n -= m;
40         memset(sg,-1,sizeof(sg));
41         for(int i = 0;i <= n;i++)
42             sg[i] = mex(i);
43         if(sg[n] == 0)
44            printf("Case #%d: aekdycoin\n",iCase);  //后手胜
45         else
46            printf("Case #%d: abcdxyzk\n",iCase);
47
48     }
49
50
51     return 0 ;
52 }

时间: 2024-10-08 03:55:28

HDU 3980 (SG 环变成链 之前的先手变成后手)的相关文章

hdu 2999 sg函数(简单博弈)

Stone Game, Why are you always there? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 393    Accepted Submission(s): 132 Problem Description "Alice and Bob are playing stone game...""E

hdu 5727 二分图+环排列

Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2423    Accepted Submission(s): 766 Problem Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang e

HDU Aragorn&#39;s Story -树链剖分

HDU Aragorn's Story Problem Description Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who want to invade his kingdom. As Aragorn knows, the enemy has N camps out of his k

【BZOJ-2937】建造酿酒厂 前缀和 + 展环为链 + 乱搞

2937: [Poi2000]建造酿酒厂 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 70  Solved: 24[Submit][Status][Discuss] Description Abstinence岛上的居民很喜欢饮用纯酿的啤酒.迄今为止,他们都是从波兰进口啤酒,自己不生产.但今年岛上的一个城市决定建造一个酿酒厂,供给其他城市的啤酒需求. 岛上所有的城市都环绕在海岸线上,相邻两城之间用高速公路连接(也就是说,它们近似分布在一个圆上).

HDU 1016 素数环(深搜)

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25134 Accepted Submission(s): 11222 Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1,

HDU 3980 Paint Chain(博弈 SG)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3980 Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one p

hdu 3980 Paint Chain sg函数

题目链接 给一个长度为n的环, 两个人轮流涂色, 每次涂m个连续的, 无法继续涂了就输. 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define pb(x) push_back(x) 4 #define ll long long 5 #define mk(x, y) make_pair(x, y) 6 #define lson l, m, rt<<1 7 #define mem(a) memset(a, 0, sizeo

HDU 3980 Paint Chain(SG函数)

Problem Description: Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unab

HDU 5044 Tree(树链剖分)

HDU 5044 Tree 题目链接 就简单的树链剖分,不过坑要加输入外挂,还要手动扩栈 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N = 100005; #pragma comment(linker, "/STACK:1024000000,1024000000"