Game with a Strip

Time limit: 2.0 second
Memory limit: 64 MB
There is a strip 1 × n with two sides. Each square of the strip (their total amount is 2nnsquares 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.
分析:预处理出每个点向右的边界;
   然后dfs判断即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e6+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
inline void umax(int &p,int q){if(p<q)p=q;}
inline void umin(int &p,int q){if(p>q)p=q;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,to[maxn];
char a[maxn];
int dfs(int l,int r,int cnt)
{
if(to[l]>=r)
{
if(a[l]=='A')return ;
else return ;
}
if((r-l+)/%==)return ;
int mid=l+r>>,a=dfs(l,mid,cnt^),b=dfs(mid+,r,cnt^);
if(cnt==)
{
if(a==||b==)return ;
else if(!a||!b)return ;
else return ;
}
else
{
if(a==||b==)return ;
else if(!a||!b)return ;
else return ;
}
}
int main()
{
int i,j;
scanf("%d%s",&n,a);
scanf("%s",a+n);
n<<=;
for(i=n-;i>=;i--)
{
if(a[i]==a[i+])to[i]=to[i+];
else to[i]=i;
}
int ok=dfs(,n-,);
if(ok==)puts("Draw");
else if(ok==)puts("Alice");
else puts("Bob");
return ;
}

最新文章

  1. UIViewController生命周期
  2. swift禁用webView对H5中数字,链接,日期,地址,电话号码做解析
  3. GridView合并表头、多重表头(转)
  4. perl小记
  5. JQuery文件上传插件uploadify在MVC中Session丢失的解决方案
  6. spring声明式事务
  7. hibernate中session的获取使用以及其他注意事项
  8. Java Day03 面向对象程序设计
  9. java基础(四):谈谈java中的IO流
  10. Linux shell编程:状态变量
  11. iOS基于B站的IJKPlayer框架的流媒体探究
  12. python常用内置函数详解
  13. 剑指Offer 49. 把字符串转换成整数 (字符串)
  14. hdu1423LCIS zoj2432 必须掌握!
  15. LeetCode28.实现strStr()
  16. 浅谈transient关键字
  17. python基础教程1:入门基础知识
  18. WordPress主题开发:优化标题
  19. Qt5.3.1 静态编译的configure
  20. 2017年P4中国峰会北京站 会议小结

热门文章

  1. 组合数们&amp;&amp;错排&amp;&amp;容斥原理
  2. [POI 2008] BLO
  3. B1001 狼抓兔子 最小割
  4. bzoj 1800 &amp; 洛谷 P2165 [AHOI2009]飞行棋 —— 模拟
  5. 逻辑回归 C++
  6. 洛谷P1894 [USACO4.2]完美的牛栏The Perfect Stall(二分图)
  7. layui日期输入框
  8. centos7安装python3.7和ipython
  9. 基于NPOI的扩展
  10. Super超级ERP系统---(9)订单管理--订单拣货