Game FZU - 2275 (无需count版kmp)

Alice and Bob is playing a game.

Each of them has a number. Alice’s number is A, and Bob’s number is B.

Each turn, one player can do one of the following actions on his own number:

  1. Flip: Flip the number. Suppose X = 123456 and after flip, X = 654321

  2. Divide. X = X/10. Attention all the numbers are integer. For example X=123456 , after this action X become 12345(but not 12345.6). 0/0=0.

Alice and Bob moves in turn, Alice moves first. Alice can only modify A, Bob can only modify B. If A=B after any player’s action, then Alice win. Otherwise the game keep going on!

Alice wants to win the game, but Bob will try his best to stop Alice.

Suppose Alice and Bob are clever enough, now Alice wants to know whether she can win the game in limited step or the game will never end.

#include 
#include 
#include 
#include 
using namespace std;
char s[1000005],t[1000005],tmp[1000005];
int nextl[1000005];
int ls,lt;
void getnext()
{
    nextl[0]=-1;
    for(int i=1;i-1)
            j=nextl[j];
        nextl[i]=(t[j+1]==t[i])?j+1:-1;
    }
}
int kmp(char *a,char *b)
{
    getnext();
    int sum=0,i=0,j=0;
    while(ils) { printf("Bob\n"); continue; }
        if(kmp(s,t) || !strcmp(t,"0")) {printf("Alice\n"); continue;}  //比较两个字符串设这两个字符串为str1,str2,若str1==str2,则返回零;若str1str2,则返回正数
//如果t字符串是0,那么一定是Alice赢
        reverse(t,t+lt);  //这个翻转用法第一次碰到
        if(kmp(s,t)) {printf("Alice\n"); continue;}
        printf("Bob\n");
    }
    return 0;
}

你可能感兴趣的:(Game FZU - 2275 (无需count版kmp))