There is a strip 1 × n with two sides. Each square of the strip (their total amount is 2nn squares on each side) is painted in one of two colors (let’s call them A and B). Alice and Bob play a game. Alice makes the first turn. On each turn, a player can bend the strip in half with the fold passing on the divisions of the squares (i.e. the turn is possible only if the strip has an even length). Bending the strip can be done either inwards or outwards. If the strip has become completely one color after the next turn, then the winner is the player whose color is it (A refers to Alice, B to Bob). If the current player has no legal moves, but no one has won, the game ends with a draw.
Who will win if both players play optimally? This means that each player tries to win; if it is not possible, to achieve a draw.

Input

The first line contains an integer n that is the length of the strip (1 ≤ n ≤ 5 · 105).
The next two lines contain two strings of letters “A” and “B” with lengths n, describing two sides of the strip. The letters that are under each other, correspond to the different sides of the same square.

Output

If Alice wins, output “Alice”. If Bob wins, output “Bob”. If the game ends with a draw, output “Draw”.

Samples

input output
4
BBAA
BABB
Bob
3
AAA
BBB
Draw
2
AA
BB
Alice

Notes

In the first example, Alice starts the game with the strip BBAA/BABB. After her turn she can get the strip BB/AA or BB/AB. In both cases, Bob can win by getting the strip B/B.
In the second example, Alice can’t make even the first turn, so the result is a draw.
In the third example, Alice wins by the first move, getting the stripe A/A from the strip AA/BB.
Problem Author: Nikita Sivukhin
Problem Source: Ural FU Junior Championship 2016

题意:有初始长度为2*N的字符串,上面只有‘A’或者‘B’,每次可以沿对角线翻折,如果翻折后全部为‘A’,则Alice胜利;全部为‘B’则Bob胜利。如果翻折前字符串长度不为偶数则为平局。

思路:翻折等效于覆盖:即[1,2N]翻折后本来应该是[N,1]或者[2*N,N+1];但是我们实际上不能模拟翻转操作(复杂度有点高,虽然好像NlogN也可以过)。这里,我们考虑翻折操作等效于覆盖操作后为[1,N]或者[N+1,2*N]。

1,判定一个区间是否颜色全部为‘A’,我们用前缀和判定,如果suma[R]-sum[L-1]==R-L+1,则全为‘A’;  ‘B’同理。

2,然后对于当前区间,我们考虑两种子情况:两种子情况都不利,则不利;有一个有利,则有利。 (博弈的思想)

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
char c[maxn]; int sum1[maxn],sum2[maxn];
int judge(int L,int R,int opt)
{
if((R-L+)%!=) return ;
if(sum1[R]-sum1[L-]==R-L+) return ; //全A
if(sum2[R]-sum2[L-]==R-L+) return ; //全B
int Mid=(L+R)/;
int lson=judge(L,Mid,-opt);
int rson=judge(Mid+,R,-opt);
if(lson==opt||rson==opt) return opt; //至少有一个必胜态
if(lson==rson&&lson==-opt) return -opt; //全为必输态
return ; // 平局
}
int main()
{
int N; scanf("%d",&N);
scanf("%s",c+); scanf("%s",c+N+);
for(int i=;i<=N+N;i++){
sum1[i]=sum1[i-]+(c[i]=='A'?:);
sum2[i]=sum2[i-]+(c[i]=='B'?:);
}
int ans=judge(,*N,);
if(ans==) printf("Alice\n");
if(ans==) printf("Bob\n");
if(ans==) printf("Draw\n");
return ;
}

最新文章

  1. python学习笔记三 深浅copy,扩展数据类型(基础篇)
  2. 转载: C++ 转换构造函数 和 类型转换函数
  3. hdu 5591 ZYB&#39;s Game 博弈论
  4. 搭建一个全栈式的HTML5移动应用框架(纯干货,亲!)
  5. iOS屏幕尺寸和分辨率
  6. winform Config文件操作
  7. Apache Shiro入门实例
  8. TortoiseSVN搭建本地版本库及简单操作使用
  9. bzoj2243-染色(动态树lct)
  10. 使用JDom解析XML文档模拟Spring的配置文件解析
  11. cuda学习笔记——deviceQuery
  12. antlr v4 使用指南连载1——简介
  13. CentOS7 设置主机名及IP映射
  14. plink命令
  15. 微信jssdk常见错误及解决方法
  16. c++11 关于typelist的foreach
  17. scikit-learn的线性回归模型
  18. u3d资源打包只能打包场景材质,不能打包脚本
  19. 使用JSON实现分页
  20. OCR技术浅探: 光学识别(3)

热门文章

  1. python020 Python3 OS 文件/目录方法
  2. Git x SVN 当前工作流程
  3. HDU1213最简单的并查集问题
  4. Codeforces603E - Pastoral Oddities
  5. bzoj5108 [CodePlus2017]可做题 位运算dp+离散
  6. 深入理解计算机操作系统——12章:多进程,IO多路复用
  7. T1503 愚蠢的宠物 codevs
  8. 【永久激活,视频教程,超级详细】IntelliJ idea 2018.3安装+激活+汉化
  9. Java实验--课上提到的随机数生成原理简单实现(不利用库生成随机数的简单算法)
  10. QT程序--CS1.6文件整理及安装器