codechef AUG17 T4 Palindromic Game

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会胜利

时间: 2024-10-26 07:08:37

codechef AUG17 T4 Palindromic Game的相关文章

codechef AUG17 T1 Chef and Rainbow Array

Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. An array is Rainbow if it has the following structure: First a1 elements equal 1.

codechef AUG17 T3 Greedy Candidates

Greedy Candidates Problem Code: GCAC The placements/recruitment season is going on in various colleges. The interviews are over, and each company has selected some students. But since each student can end up finally in at most one company, a student

codechef AUG17 T5 Chef And Fibonacci Array

Chef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i ≥ 1, if Ai > 0, Ai+1 > 0, and Ai+2 exists, then he can decrease both Ai, andAi+1 by one and increase Ai+2 by one. If Ai+2 doesn't exist, but Ai >

codechef AUG17 T2 Chef and Mover

Chef and Mover Problem Code: CHEFMOVR Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN. Bad news: Snuffles only loves to play with an array in which all the elements

codechef T4 IPC Trainers

IPCTRAIN: 训练营教练题目描述 本次印度编程训练营(Indian Programming Camp,IPC)共请到了 N 名教练.训练营的日 程安排有 M 天,每天最多上一节课.第 i 名教练在第 Di 天到达,直到训练营结束才离开.第 i 名 教练希望上 Ti 节课.要是少上了课,那么教练会感到扎心,每少上一节,扎心值就会加 Si. 作为主办方,你希望最小化所有教练的扎心值之和.输入格式输入的第一行包含一个整数 T,代表测试数据的组数.接下来是 T 组数据. 每组数据的第一行包含两个整

codechef MAY18 div2 部分题解

T1 https://www.codechef.com/MAY18B/problems/RD19 刚开始zz了,其实很简单. 删除一个数不会使gcd变小,于是就只有0/1两种情况 T2 https://www.codechef.com/MAY18B/problems/XORAGN 我们可以把B序列看做一个矩阵 那么$A(i,j)$和$A(j,i)$会抵消掉 因此答案就是$\sum_1^n A(i,i) + A(i,i)$ T3 https://www.codechef.com/MAY18B/pr

[string]Longest Palindromic Substring

Total Accepted: 82026 Total Submissions: 379898 Difficulty: Medium Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. Subscrib

LeetCode OJ:Longest Palindromic Substring(最长的回文字串)

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 玩了两天dota2,罪过罪过,还是应该老老实实刷题啊. 题目求得是最长的回文子串,这里使用的是暴力的解法,也就是解决两种回文"asdsa"以

USACO 1.2 Palindromic Squares

Palindromic SquaresRob Kolstad Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that