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 ;
}

URAL2104. Game with a Strip(博弈)的更多相关文章

  1. Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)

    D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...

  2. hdu----(1849)Rabbit and Grass(简单的尼姆博弈)

    Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 5754 Life Winner Bo 组合博弈

    Life Winner Bo Problem Description   Bo is a "Life Winner".He likes playing chessboard gam ...

  4. python strip()函数 介绍

    python strip()函数 介绍,需要的朋友可以参考一下   函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm)        删除s字符串中开头.结尾处,位于 rm删除 ...

  5. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  6. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  7. 51nod1072(wythoff 博弈)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1072 题意: 中文题诶~ 思路: 博弈套路是有的, 找np局 ...

  8. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  9. 【转】ACM博弈知识汇总

    博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...

随机推荐

  1. Go 方法和接收者

    package main import ( "fmt" ) //面向对象 //go仅支持封装,不支持继承和多态 //go语言中没有class,只要struct //不论地址还是结构 ...

  2. NOIP2013D1T3货车运输(最大生成树+倍增lca)

    传送门 这道题,先用kruskal求一遍图中的最大生成树. 然后,倍增求lca,求lca的同时求出边权的最小值. #include <cstring> #include <cstdi ...

  3. JPos学习

    基于JPos的消息交换系统 消息交换系统需求解读 消息交换系统不不是一个具体的业务系统,而是业务系统的运转的基础框架: 他的运转是体现在报文交换上的: 要定义一个可被不同业务系统使用的报文规范: 报文 ...

  4. Codeforces936D. World of Tank

    $n \leq 1e9$,$n*2$的网格里有$m_1+m_2 \leq 1e6$个障碍物,现有一坦克从$(0,1)$出发要到$(n+1,1/2)$,他每秒可以换行(纵坐标1变2或2变1)也可以发炮弹 ...

  5. Xcode 全局搜索失效的问题

    早上手一快不知点了什么,然后全局搜索的功能就不起作用了.百度了一下才知道,原来把搜索范围给改了,改回来如下:

  6. APP后端处理视频的方案

    在当前的app应用中,到处都能看到视频的身影,例如,在社交类的app上,用户可以拍摄属于自己的小视频,并发布到相应得栏目,增加和好友们互动的机会. 后台常见的视频处理有以下几种: ·          ...

  7. Eclipse Explorer插件快速打开项目文件在系统资源管理器

    官网:https://github.com/Jamling/eclipse-explorer 安装: 1.在线安装 [Help]->[Eclipse Marketplace]搜索:Eclipse ...

  8. python执行

    转载:https://www.cnblogs.com/zflibra/p/4180796.html

  9. JAVA学习(一):Java介绍及其平台、开发环境的配置与搭建

    Java介绍及其平台.开发环境的配置与搭建 1.Java的介绍 Java是一种面向对象的编程语言,具有跨平台.可移植.分布式.简单.可扩展等诸多特性.Java能够进行桌面应用.Web应用.分布式系统及 ...

  10. How do you check if a variable is an array in JavaScript? [duplicate]

    https://stackoverflow.com/questions/767486/how-do-you-check-if-a-variable-is-an-array-in-javascript ...