题面

传送门

题解

博弈论的前提是双方都是绝顶聪明的人

所以这种题目显然不是我应该做的

题解

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
int read(char *s){
R int len=0;R char ch;while(((ch=getc())>'Z'||ch<'A'));
for(s[++len]=ch;(ch=getc())>='A'&&ch<='Z';s[++len]=ch);
return s[len+1]='\0',len;
}
const int N=1e6+5;
struct eg{int v,nx;}e[N<<1];int head[N],deg[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot,++deg[v];}
char s[N];int n;
void solve(){
n=read(),tot=0;
memset(head,0,4*(n+1)),memset(deg,0,4*(n+1));
for(R int i=1,u,v;i<n;++i)u=read(),v=read(),add(u,v),add(v,u);
read(s);
if(n<3)return puts("Draw"),void();
if(n==3){
int cnt=(s[1]=='W')+(s[2]=='W')+(s[3]=='W');
puts(cnt>1?"White":"Draw");
return;
}
fp(i,1,n)if(s[i]=='W')head[++n]=0,add(i,n),add(n,i),deg[n]=3;
int cc=0;
fp(u,1,n)if(deg[u]>3)return puts("White"),void();
else if(deg[u]==3){
int cnt=0;
go(u)cnt+=deg[v]>=2;
if(cnt>=2)return puts("White"),void();
++cc;
}
puts((cc==2&&(n&1))?"White":"Draw");
}
int main(){
// freopen("testdata.in","r",stdin);
int T=read();
while(T--)solve();
return 0;
}

CF1110G Tree-Tac-Toe(博弈论)的更多相关文章

  1. Principle of Computing (Python)学习笔记(7) DFS Search + Tic Tac Toe use MiniMax Stratedy

    1. Trees Tree is a recursive structure. 1.1 math nodes https://class.coursera.org/principlescomputin ...

  2. POJ 2361 Tic Tac Toe

    题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...

  3. 【leetcode】1275. Find Winner on a Tic Tac Toe Game

    题目如下: Tic-tac-toe is played by two players A and B on a 3 x 3 grid. Here are the rules of Tic-Tac-To ...

  4. 2019 GDUT Rating Contest III : Problem C. Team Tic Tac Toe

    题面: C. Team Tic Tac Toe Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. [CareerCup] 17.2 Tic Tac Toe 井字棋游戏

    17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...

  6. Epic - Tic Tac Toe

    N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...

  7. python 井字棋(Tic Tac Toe)

    说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...

  8. ACM-Team Tic Tac Toe

    我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...

  9. LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game

    地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...

  10. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

随机推荐

  1. swarm调度

    Swarm filters Configure the available filters 过滤器分为两类,即节点过滤器和容器配置过滤器. 节点过滤器对Docker主机的特性或Docker守护程序的配 ...

  2. Redis 基础操作

    [Redis 基础操作] 1.ECHO message. Returns message. 2.PHING Returns PONG if no argument is provided, other ...

  3. python's import mechanism

    [python's import mechanism] 问题描述: [A.py] from B import D class C:pass [B.py] from A import C class D ...

  4. Unix高级编程Note1

    [Unix Notes] 1./etc/passwd 2.extern int errno; 3.限制, limit.h 4.文件原子操作:O_EXCL & O_CREAT 5.stat操作 ...

  5. Python_02-控制语句

    目录:  1         控制结构...  1.1      分支语句...  1.1.1   if语句的嵌套...  1.2      for循环...  1.2.1   Python 循环中的 ...

  6. jQuery插件Highcharts

    Highcharts 是一个用纯 JavaScript 编写的一个图表库, 能够很简单便捷的在 Web 网站或是 Web 应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用. ...

  7. Python 入门学习(壹)上机时间提醒

    基于 Udacity 的 Python 入门课程 Programming Foundations with Python 基于 Python 2.7 控制台版本 思路 Project 1 是一个时间提 ...

  8. shell编程9*9乘法表

    </pre>脚本内容<pre name="code" class="plain">#!/bin/bash for i in " ...

  9. oracle存储过程和游标参考

    oracle open cursor forhttp://www.itpub.net/thread-1874683-1-1.html

  10. java 控制反转和依赖注入的理解

    开始好好学习java基础和思想~ 控制反转(IOC)是Spring框架的核心思想,用我自己的话说,就是你要做一件事,别自己可劲new了,你就说你要干啥,然后外包出去就好~ 依赖注入(DI) 在我浅薄的 ...