大概就是dfs?当前区间(l,r)的答案可以由(l,m)和(m+1,r)区间推出,如果某个区间已经完全被某种颜色覆盖,那么就返回该颜色。否则按照递归层数判定,奇数层Alice占优势,只需左右区间中一者为必胜即可,而Bob需要左右区间均为其必胜色才可以。无解判一下即可。感觉还是很巧妙。

There is a strip 1 × n with two sides. Each square of the strip (their total amount is 2 nn squares on each side) is painted in one of two colors (let’s call them Aand 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 ( Arefers 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 · 10 5).
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”.

Example

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.
#include<cstdio>
int n,rsz[1000010];
char a[1000010];
int dfs(int l,int r,int dep)
{
if(rsz[l]>=r)
{
if(a[l]=='A')
return 1;
if(a[l]=='B')
return 2;
return 0;
}
if(((r-l+1)/2)%2!=0)
return 0;
int m=(l+r>>1);
int f1=dfs(l,m,dep^1),f2=dfs(m+1,r,dep^1);
if(!dep)
{
if(f1==1 || f2==1)
return 1;
if(f1==0 || f2==0)
return 0;
// if(f1==2 && f2==2)
return 2;
}
else
{
if(f1==2 || f2==2)
return 2;
if(f1==0 || f2==0)
return 0;
// if(f1==1 && f2==1)
return 1;
}
}
int main()
{
//freopen("e.in","r",stdin);
scanf("%d",&n);
scanf("%s",a+1);
scanf("%s",a+1+n);
n<<=1;
rsz[n]=n;
for(int i=n-1;i>=1;--i)
if(a[i]==a[i+1])
rsz[i]=rsz[i+1];
else
rsz[i]=i;
int f=dfs(1,n,0);
if(f==0)
puts("Draw");
else if(f==1)
puts("Alice");
else
puts("Bob");
return 0;
}

【DFS】URAL - 2104 - Game with a Strip的更多相关文章

  1. 【BZOJ1814】Ural 1519 Formula 1 (插头dp)

    [BZOJ1814]Ural 1519 Formula 1 (插头dp) 题面 BZOJ Vjudge 题解 戳这里 上面那个链接里面写的非常好啦. 然后说几个点吧. 首先是关于为什么只需要考虑三进制 ...

  2. 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】

    目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...

  3. 【BZOJ1814】Ural 1519 Formula 1 插头DP

    [BZOJ1814]Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数.(n,m<=12) 题解:插头DP板子题,刷板 ...

  4. Kattis - glitchbot 【DFS】

    Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...

  5. HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))

    度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. 【dfs】P1331 海战

    题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...

  7. 【dfs】p1731 生日蛋糕

    1441:[例题2]生日蛋搞 [题目描述] 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体.设从下往上数第i(1≤i≤M)层蛋糕是半径为Ri, 高 ...

  8. 【dfs】LETTERS

    1212:LETTERS [题目描述] 给出一个roe×colroe×col的大写字母矩阵,一开始的位置为左上角,你可以向上下左右四个方向移动,并且不能移向曾经经过的字母.问最多可以经过几个字母. [ ...

  9. 洛谷P1605 迷宫【dfs】

    题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...

随机推荐

  1. POJ 3179 Corral the Cows

    Corral the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1352   Accepted: 565 De ...

  2. js中连写两个?:三元运算符语法解释

    在angular 源码中有连写两个三元运算符的代码: var hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() :$loc ...

  3. bzoj4589 FWT xor版本

    4589: Hard Nim Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 865  Solved: 484[Submit][Status][Disc ...

  4. 一串跟随鼠标的DIV

    div跟随鼠标移动的函数: <!DOCTYPE HTML><html><head> <meta charset="utf-8"> & ...

  5. MySQL 8.0.11 中使用 grant ... identified by 时 error 1064 near 'identified by '密码'' at line 1

    (1)问题:     当使用 grant 权限列表 on 数据库 to '用户名'@'访问主机' identified by '密码'; 时会出现"......near 'identifie ...

  6. The 'brew link' step did not complete successfully

    在mac 上更新node时遇到了一系列的问题: 卸载node重新安装之后提示: The 'brew link' step did not complete successfully 其实这里已经给出了 ...

  7. [bzoj3990][SDOI2015]排序-搜索

    Brief Description 小A有一个1-2^N的排列A[1..2^N],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的i(1<=i<= ...

  8. python函数篇:名称空间、作用域和函数的嵌套

    一.名称空间:(有3类) (1)内置名称空间(全局作用域) (2)全局名称空间(全局作用域) (3)局部名称空间(局部作用域) 关于名称空间的查询: x=1 def func(): print('fr ...

  9. 在opensuse 中安装视频解码器

    最近由于需要32位的linux系统使用,很多版本的linux都不再发布32的安装镜像了,有一些又不是很熟悉,我熟悉的manjaro发布的32镜像又不是kde桌面,最后发现opensuse的滚动版本,即 ...

  10. jQuery中操作样式

    操作行间样式 // 获取div的样式 $("div").css("width"); $("div").css("color&quo ...