题目链接:https://www.codechef.com/problems/PALINGAM
算是博弈论的题,但主要就是猜结论+乱搞
可以一步步考虑
第一步没有什么输赢
第二步如果B给出了A给出的字符就赢了,那么如果A中所有出现过的字符都在B中出现过,则B稳赢
第三步如果A给出了第一步给出的字符就赢了,当然前提是第二步B未赢,所以如果A中存在一个出现次数≥2的字符且不曾在B中出现过,则A稳赢
第三步还有一种可能,就是如果A能给出B给出的字符,那么显然也可以构成XYX形式从而赢了,所以在第二步B未赢的情况下,B中的字符都在A中出现过,则A稳赢
从第四步开始就不确定了,可以相互捣乱,构不成回文,但是很难出现输赢,最后是算B赢。
贴代码
var Q,t,i,j,bo:longint;
s1,s2:ansistring;
h1,h2:array[0..30]of longint;
begin
// assign(input,'1.in');reset(input);
// assign(output,'1.out');rewrite(output);
readln(Q);
for t:=1 to Q do
begin
readln(s1);
readln(s2);
fillchar(h1,sizeof(h1),0);
fillchar(h2,sizeof(h2),0);
for i:=1 to length(s1) do inc(h1[ord(s1[i])-96]);
for i:=1 to length(s2) do inc(h2[ord(s2[i])-96]);
bo:=0;
for i:=1 to 26 do if (h1[i]>0)and(h2[i]=0) then bo:=1;
if bo=0 then begin
writeln('B');
continue;
end
else begin
bo:=0;
for i:=1 to 26 do if (h1[i]>1) and (h2[i]=0) then begin
bo:=1;
break;
end;
if bo=1 then begin writeln('A');continue; end;
end;
bo:=0;
for i:=1 to 26 do
if (h2[i]>0)and(h1[i]=0) then bo:=1;
if bo=0 then begin writeln('A');continue;end;
writeln('B');
end;
// close(input);close(output);
end.
-
【写的有漏洞的,欢迎路过大神吐槽】
2017/08/20 08:35:27
Ending.