zoukankan      html  css  js  c++  java
  • HDU 3970 Paint Chain (博弈,SG函数)

    Paint Chain

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 909    Accepted Submission(s): 325


    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 unable to paint in his turn lose the game. Aekdycoin will take the first move.

    Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
     
    Input
    First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
     
    Output
    For each case, print "Case #idx: " first where idx is the case number start from 1, and the name of the winner.
     
    Sample Input
    2 3 1 4 2
     
    Sample Output
    Case #1: aekdycoin Case #2: abcdxyzk
     
    Author
    jayi
     
    Source

    用SG函数搞一遍就可以了。

     1 /* ***********************************************
     2 Author        :kuangbin
     3 Created Time  :2013-11-17 19:20:19
     4 File Name     :E:2013ACM比赛练习2013-11-17H.cpp
     5 ************************************************ */
     6 
     7 #include <stdio.h>
     8 #include <string.h>
     9 #include <iostream>
    10 #include <algorithm>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <math.h>
    17 #include <stdlib.h>
    18 #include <time.h>
    19 using namespace std;
    20 const int MAXN = 1010;
    21 int sg[MAXN];
    22 bool vis[MAXN];
    23 int m;
    24 int mex(int n)
    25 {
    26     if(sg[n] != -1)return sg[n];
    27     if(n < m)return sg[n] = 0;
    28     memset(vis,false,sizeof(vis));
    29     for(int i = m;i <= n;i++)
    30         vis[mex(i-m)^mex(n-i)] = true;
    31     for(int i = 0;;i++)
    32         if(vis[i] == false)
    33         {
    34             sg[n] = i;
    35             break;
    36         }
    37     return sg[n];
    38 }
    39 
    40 int main()
    41 {
    42     //freopen("in.txt","r",stdin);
    43     //freopen("out.txt","w",stdout);
    44     int T;
    45     int n;
    46     scanf("%d",&T);
    47     int iCase = 0;
    48     while(T--)
    49     {
    50         scanf("%d%d",&n,&m);
    51         iCase++;
    52         if(n < m)
    53         {
    54             printf("Case #%d: abcdxyzk
    ",iCase);
    55             continue;
    56         }
    57         n -= m;
    58         memset(sg,-1,sizeof(sg));
    59         for(int i = 0;i <= n;i++)
    60             sg[i] = mex(i);
    61         if(sg[n] == 0)printf("Case #%d: aekdycoin
    ",iCase);
    62         else printf("Case #%d: abcdxyzk
    ",iCase);
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    rsync文件备份同步
    程序员的家!我终于拥有自己的blog了!!!
    使用APMServ服务配置如何进行Wordpress本地伪静态设置
    清理Windows.edb文件释放C盘空间(原创)
    不知道按到什么键了,代码前面出现了省略号,使用Ctrl+E+S恢复
    (转)c/c++资源(源码,开发工具)
    EditPlus自动换行
    不用外部软件,直接对文件批量重命名(转)
    C# 实现自定义处理窗体按键(整理)
    C# 控件名称缩写介绍(转)
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3428470.html
Copyright © 2011-2022 走看看