2015浙江理工校赛C String Game

题解

多试几次就能发现规律了…转一个题解的解释

比较字符串,a字符串,与b字符串,可以证明的b字符串在a字符串中间,才是Alice赢,因为Bob从左边拿一个,Alice就可以从右边拿一个,Bob从右边拿一个,Alice就可以从左边拿一个,保证b字符串一直在a字符串中间,但是还有两种情况,就是如果有两个字符串与b匹配,那么只要这两个字符串关于a的中间对称,且两个字符串的位置差不超过2,那么也是Alice赢,因为,Bob拿完一个后,Alice可以在相同方向拿,所以字符串可以从中间向左(或右)偏移1格

代码

#include <cstdio>
#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <bitset>
#define MAX 100000
#define LL long long
using namespace std;
int cas=1,T;
char a[5*MAX+10],b[5*MAX+10];
int main()
{
    //freopen("in","r",stdin);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s%s",a,b);
        int la=strlen(a),lb=strlen(b),flag=0,d;
        d=(la-lb)>>1;
        if((la-lb)&1)
        {
            if(strncmp(a+d+1,b,lb)==0&&strncmp(a+d,b,lb)==0) flag=1;
        }
        else
        {
            if(strncmp(a+d,b,lb)==0) flag=1;
            if(la>lb) if(strncmp(a+d+1,b,lb)==0&&strncmp(a+d-1,b,lb)==0) flag=1;
        }
        flag?puts("Alice"):puts("Bob");
    }
    return 0;
}

题目

String Game

Time Limit: 1 Sec Memory Limit: 128 MB

Description

Alice and Bob are playing the following game with strings of letters.

Before the game begins, an initial string and a target string are decided. The initial string is at least as long as the target string. Then, Alice and Bob take turns, starting with the initial string. Bob goes first. In each turn, the current player removes either the first or the last letter of the current string. Once the length of the current string becomes equal to the length of the target string, the game stops. If the string at the end of the game is equal to the target string, Alice wins the game; otherwise Bob wins.

Determine who will win the game if both players are playing optimally.

Input

Each test case starts with N, the number of inputs to process. Each input consists of one line, which contains the initial string, followed by a space, followed by the target string. Each string consists of only lowercase letters. The total input length will be less than 500000 characters.

Output

For each input, output the winner, which will either be Alice or Bob.

Sample Input

5
aba b
bab b
aaab aab
xyz mnk
xyz xyz

Sample Output

Alice
Alice
Bob
Bob
Alice

你可能感兴趣的:(2015浙江理工校赛C String Game)