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会胜利
codechef AUG17 T4 Palindromic Game的更多相关文章
- 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 ...
- codechef AUG17 T1 Chef and Rainbow Array
Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some array ...
- 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 ...
- codechef AUG17 T3 Greedy Candidates
Greedy Candidates Problem Code: GCAC The placements/recruitment season is going on in various colleg ...
- codechef T4 IPC Trainers
IPCTRAIN: 训练营教练题目描述 本次印度编程训练营(Indian Programming Camp,IPC)共请到了 N 名教练.训练营的日 程安排有 M 天,每天最多上一节课.第 i 名教练 ...
- codechef MAY18 div2 部分题解
T1 https://www.codechef.com/MAY18B/problems/RD19 刚开始zz了,其实很简单. 删除一个数不会使gcd变小,于是就只有0/1两种情况 T2 https:/ ...
- [Codechef - AASHRAM] Gaithonde Leaves Aashram - 线段树,DFS序
[Codechef - AASHRAM] Gaithonde Leaves Aashram Description 给出一棵树,树的"N"节点根植于节点1,每个节点'u'与权重a[ ...
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- 使用T4模板生成不同部署环境下的配置文件
在开发企业级应用的时候,通常会有不同的开发环境,比如有开发环境,测试环境,正式环境,生产环境等.在一份代码部署到不同环境的时候,不同环境的配置文件可能需要根据目标环境不同而不同.比如在开发环境中,数据 ...
随机推荐
- SummerVocation_Learning--java的String 类
java中String属于java.lang的package包,是一个类.代表不可变的字符序列. String类的常见构造方法: String(String original),创建一个对象为orig ...
- jrtplib库使用简解
RTP有效载荷类型即时间截解释 =============================== https://www.cnblogs.com/wyqfighting/archive/2013/03/ ...
- ElasticSearch High Level REST API【6】获取集群信息
ElasticSearch 可以通过info()方法检索群集信息: public void info(){ RestHighLevelClient client = elasticClient.get ...
- Python的集合与字典练习
集合与字典练习 question1 问题描述:有一个列表,其中包括 10 个元素,例如这个列表是[1,2,3,4,5,6,7,8,9,0],要求将列表中的每个元素一次向前移动一个位置,第一个元素到列表 ...
- Keywords Search HDU - 2222 ( ac自动机)模版题
Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- TCP/IP网络编程之多播与广播
多播 多播方式的数据传输是基于UDP完成的,因此,与UDP服务端/客户端的实现非常接近.区别在于,UDP数据传输以单一目标进行,而多播数据同时传递到加入(注册)特定组的大量主机.换言之,采用多播方式时 ...
- mybatis特殊字符处理
在mybatis 的mapper.xml文件中特殊字符处理方式 仅供参考 出处:http://yaobenzhang.blog.163.com/blog/static/214395113201561 ...
- 1 - JVM随笔分类(java虚拟机的内存区域分配(一个不断记录和推翻以及再记录的一个过程))
java虚拟机的内存区域分配 在JVM运行时,类加载器ClassLoader在加载到类的字节码后,交由jvm的执行引擎处理, 执行过程中需要空间来存储数据(类似于Cpu及主存),此时的这段空间的分 ...
- JS空数组的判断
前言 最近在做一个mini项目,被大神各种鄙视,基础知识确实是不扎实,加油加油.好了,不多废话,抽空写写遇到的两个知识点,就记录下来,写博客还是能帮忙整理记录的,不然过了就忘记了. input监听值改 ...
- 牛客网python试题-错误整理-20180711
######## >>>[3] in [1,2,3,4] False >>>3 in [1,2,3,4] True ######## x = (y = z + 1) ...