程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu3980 Paint Chain------sg 環--鏈 一排石子分成若干堆

hdu3980 Paint Chain------sg 環--鏈 一排石子分成若干堆

編輯:C++入門知識

Paint Chain
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 696    Accepted Submission(s): 252


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
2011 Multi-University Training Contest 14 - Host by FZU
 
把環轉成鏈
[cpp]
#include<iostream> 
#include<cstdlib> 
#include<stdio.h> 
#include<memory.h> 
using namespace std; 
int sg[1010]; 
int m; 
int find(int x) 

    if(sg[x]>=0) return sg[x]; 
    if(x-m<0) return sg[x]=0; 
    bool g[1010]={0}; 
    for(int j=x-m;j>=0;j--) 
    g[find(j)^find(x-m-j)]=1; 
    for(int i=0;;i++) 
    if(g[i]==0) return sg[x]=i; 

int main() 

    int t,n; 
    int count=1; 
    scanf("%d",&t); 
    while(t--) 
    { 
        scanf("%d%d",&n,&m); 
        memset(sg,-1,sizeof(sg)); 
        printf("Case #%d: ",count++); 
        int ans=0; 
        if(n>=m) 
        ans=find(n-m)?0:1; 
        if(ans) puts("aekdycoin"); 
        else  puts("abcdxyzk"); 
        /*
        int ans=0;
        if(n>=m)
        ans=find(n-m);
        if(!ans) puts("aekdycoin");
        else  puts("abcdxyzk");
        寫成這樣竟然不對,這讓我很費解~
        */ 
    } 

/*
Sample Input
2
3 1
4 2
 
 
Sample Output
Case #1: aekdycoin
Case #2: abcdxyzk
 
*/ 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved