码迷,mamicode.com
首页 > 其他好文 > 详细

codechef AUG17 T4 Palindromic Game

时间:2017-08-07 22:29:25      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:building   contain   nbsp   other   make   uil   res   hat   creat   

Palindromic Game Problem Code: PALINGAM

There are two players A, B playing a game. Player A has a string s with him, and player B has string t with him. Both s and t consist only of lower case English letters and are of equal length. A makes the first move, then B, then A, and so on alternatively. Before the start of the game, the players know the content of both the strings s and t.

These players are building one other string w during the game. Initially, the string w is empty. In each move, a player removes any one character from their respective string and adds this character anywhere (at any position) in the string w. If at any stage of the game, the string w is of length greater than 1 and is a palindrome, then the player who made the last move wins.

If even after the game finishes (ie. when both s and t have become empty strings), no one is able to make the string w a palindrome, then player B wins.

Given the strings s, and t, find out which of A, B will win the game, if both play optimally.

Input

  • The first line of the input contains an integer T, corresponding to the number of test cases. The description of each testcase follows.
  • The first line of each testcase will contain the string s.
  • The second line of each testcase will contain the string t.

Output

For each test case, output "A" or "B" (without quotes) corresponding to the situation, in a new line.

Constraints

  • Subtask 1 (20 points) : 1 ≤ T ≤ 500, All characters of string s are equal, All characters of string t are equal. 1 ≤ |s| = |t| ≤ 500
  • Subtask 2 (80 points) : 1 ≤ T ≤ 500, 1 ≤ |s| = |t| ≤ 500

Example

Input:
3
ab
ab
aba
cde
ab
cd
Output:
B
A
B

Explanation

Testcase 1: If A adds ‘a‘ to w in the first move, B can add ‘a‘ and make the string w = "aa",

which is a palindrome,and hence win. S

imilarly, you can show that no matter what A plays, B can win.Hence the answer is B.

Testcase 2: Player A moves with ‘a‘, player B can put any of the character ‘c‘, ‘d‘ or ‘e‘, Now Player A can create a palindrome by adding ‘a‘.

Testcase 3: None of the players will be able to make a palindrome of length > 1. So B will win.

—————————————————————————————————————————————

 这道题就是有两个人A和B 他们每个人有一个串

(A先起手)每次一个人人能拿出自己串中剩余的字母中的一个加入现有串C的左边或者右边

当C变成一个回文串的时候游戏结束 使这个串变成回文串的一方胜利

我们考虑A起手 如果他下了一个B有的字母 那么无疑B会胜利

如果他下了一个B没有的字母 且这个字母他有两个 那么他一定胜利

不然 如果B下的这个字母A有那么A会胜利 不然不论如何下这个串都不会成为回文串

那么平局下 按提议B会胜利

codechef AUG17 T4 Palindromic Game

标签:building   contain   nbsp   other   make   uil   res   hat   creat   

原文地址:http://www.cnblogs.com/lyzuikeai/p/7301247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!