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. PTA 03-树1 树的同构 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/711 5-3 树的同构   (25分) 给定两棵树T1和T2.如果T1可以通过若干次左右 ...

  2. 字符串匹配(codevs 1404)

    题目描述 Description 给你两个串A,B,可以得到从A的任意位开始的子串和B匹配的长度.给定K个询问,对于每个询问给定一个x,求出匹配长度恰为x的位置有多少个.N,M,K<=20000 ...

  3. 【ZJOI2017 Round1练习】D2T3 counter(线段树)

    题意: 思路: 预处理出b[i]代表i位置之前比a[i]小的数的个数 以每个数为结尾的组数是线段树中(1,a[i]-1) 对于a[i]换到最后,相当于线段树中(a[i]+1,n)-- 交换后b[i]又 ...

  4. Git学习之常见错误 clone被拒绝

    Git学习之常见错误 问题: git clone 时 报错 Permission Denied (权限被拒绝). 解决方法: 需要把本地的公钥上传到服务器. 解决步骤: ①第一步,设置本地的git的用 ...

  5. freeswitch三方通话配置

    此种方法能实现,其中默认转移后按0,可进入三方通话. 用transfer只能实现代接转移. Misc. Dialplan Tools att xfer From FreeSWITCH Wiki Jum ...

  6. oracle数据库 SQL语句、内置函数大全

    1.数值函数 函数 返回值 样例 显示 CEIL(n)      大于或等于数值n的最小整数 SELECT CEIL(10.6) FROM TABLE_NAME; 11 FLOOR(n)  小于等于数 ...

  7. jenkins的代理设置,方便下载插件

    jenkins在下载插件的时候,总是网络不通,需要设置代理跨越长城 java.net.SocketTimeoutException: connect timed out Caused: java.ne ...

  8. 【Nginx】惊群问题

    转自:江南烟雨 惊群问题的产生 在建立连接的时候,Nginx处于充分发挥多核CPU架构性能的考虑,使用了多个worker子进程监听相同端口的设计,这样多个子进程在accept建立新连接时会有争抢,这会 ...

  9. LeetCode题解汇总

    陆续更新至github... https://github.com/OliveLv/LeetCode/ 

  10. JavaSE入门学习23:Java面向对象之构造方法

    学了JavaSE面向对象这一部分,也该对构造方法做一个总结了. 一构造方法 在多数情况下,初始化一个对象的终于步骤是去调用这个对象的构造方法. 构造方法负责对象的初始化工作,为 实例变量赋予合适的初始 ...