zoukankan      html  css  js  c++  java
  • hdu-3980-nim博弈/sg函数

    Paint Chain

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


    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
     

            一串长度为n的圆形珠子,每次可以找连续的m个白色珠子染色,不能操作者输,问先手状态。

       先计算出线性状态下的游戏的sg函数,再计算与真实状态的sg函数时判断sg[n-m]=sg[n-m]==0?1:0。

           由于子状态只有一种。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int sg[1010];
     4 bool vis[1010];
     5 int main(){
     6     int t,n,m,i,j,k;
     7     cin>>t;
     8     for(int cas=1;cas<=t;++cas){
     9         cin>>n>>m;
    10         printf("Case #%d: ",cas);
    11         if(n<m){
    12             puts("abcdxyzk");
    13             continue;
    14         }
    15         for(i=0;i<m;++i) sg[i]=0;
    16         for(i=m;i<=n;++i){
    17             memset(vis,0,sizeof(vis));
    18             for(j=1;j+m-1<=i;j++){
    19                 vis[sg[j-1]^sg[i-m-j+1]]=1;
    20             }
    21             for(j=0;;j++){
    22                 if(!vis[j]){
    23                     sg[i]=j;
    24                     break;
    25                 }
    26             }
    27         }
    28         for(i=0;i<=n;++i){
    29             if(sg[i]==0) sg[i]=1;
    30             else sg[i]=0;
    31         }
    32         sg[n-m]?puts("aekdycoin"):puts("abcdxyzk");
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    tableView
    ios设计模式 设计一个应用程序 笔记
    Touching the Background to close the Keyboard
    fdfd
    fdffafadf
    Declaring the Action Method
    网易公开课IOS笔记 第二课
    getters and setters
    objective c
    Google编码规范 C++ Style Guide, JavaScript Style Guide, ObjectiveC Style Guide, and Python Style Guide
  • 原文地址:https://www.cnblogs.com/zzqc/p/9328414.html
Copyright © 2011-2022 走看看