FZU 2275 Game【博弈】

来源:互联网 发布:智慧足迹数据 编辑:程序博客网 时间:2024/06/06 13:16

Problem 2275 Game

Accept: 70    Submit: 188
Time Limit: 1000 mSec    Memory Limit : 262144 KB

 Problem Description

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.

 Input

First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

For each test case: Two number A and B. 0<=A,B<=10^100000.

 Output

For each test case, if Alice can win the game, output “Alice”. Otherwise output “Bob”.

 Sample Input

411111 11 1111112345 54321123 123

 Sample Output

AliceBobAliceAlice

 Hint

For the third sample, Alice flip his number and win the game.

For the last sample, A=B, so Alice win the game immediately even nobody take a move.

 Source

第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)



思路:

1。如果a.size()<b.size(),Bob必胜

2。否则,看a有没有包含b正或者a有没有包含b逆,如果包含,Alice胜利,否则Bob胜利

注意:b==0,Alice必胜


#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#include<set>#include<algorithm>using namespace std;#define ll long long#define ms(a,b)  memset(a,b,sizeof(a))#define maxn 510const int M=1e6+10;const int inf=0x3f3f3f3f;const int mod=1e9+7;const double eps=1e-10;int i,j,k,n,m;int r1,r2,l1,l2;int mp[10][10];string a;string b;int flag;vector<int>find_substring(string p,string t,int k){    int n=p.size();    vector<int>next(n+1,0);    for(int i=1;i<n;i++){        int j=i;        while(j>0){            j=next[j];            if(p[j]==p[i]){                next[i+1]=j+1;                break;            }        }    }    vector<int>pos;    int m=t.size();    for(int i=0,j=0;i<m;i++){        if(j<n&&t[i]==p[j])j++;        else {            while(j>0){                j=next[j];                if(t[i]==p[j]){                    j++;                    break;                }            }        }        if(j==n){            pos.push_back(i-n+1);        }    }    if(k==0){      if(pos.size()>0) {printf("Alice\n");flag=1;}    }    else if(flag==0){        if(pos.size()>0&&flag==0) {printf("Alice\n");}       else  if(pos.size()==0)printf("Bob\n");    }}int main(){    int t;    scanf("%d",&t);    while(t--){         cin>>a>>b;         if(b=="0"){printf("Alice\n");continue;}        if(a.size()<b.size())printf("Bob\n");        else {         flag=0;         find_substring(b,a,0);          reverse(b.begin(),b.end());         find_substring(b,a,1);        }    }    return 0;}


原创粉丝点击