CF1110G Tree-Tac-Toe(博弈论)
题面
题解
博弈论的前提是双方都是绝顶聪明的人
所以这种题目显然不是我应该做的
//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(博弈论)的更多相关文章
- 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 ...
- POJ 2361 Tic Tac Toe
题目:给定一个3*3的矩阵,是一个井字过三关游戏.开始为X先走,问你这个是不是一个合法的游戏.也就是,现在这种情况,能不能出现.如果有人赢了,那应该立即停止.那么可以知道X的步数和O的步数应该满足x= ...
- 【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 ...
- 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 ...
- [CareerCup] 17.2 Tic Tac Toe 井字棋游戏
17.2 Design an algorithm to figure out if someone has won a game oftic-tac-toe. 这道题让我们判断玩家是否能赢井字棋游戏, ...
- Epic - Tic Tac Toe
N*N matrix is given with input red or black.You can move horizontally, vertically or diagonally. If ...
- python 井字棋(Tic Tac Toe)
说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码也是本人逐字逐句敲的. minimax算法还没完全理解,所以参考了这里的代码,并作了修改. 特点 可以选 ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- LeetCode 5275. 找出井字棋的获胜者 Find Winner on a Tic Tac Toe Game
地址 https://www.acwing.com/solution/LeetCode/content/6670/ 题目描述A 和 B 在一个 3 x 3 的网格上玩井字棋. 井字棋游戏的规则如下: ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
随机推荐
- js中__proto__, property, prototype, 对象自身属性方法和原型中的属性方法的区别
__proto__: 这个属性是实例对象的属性,每个实例对象都有一个__proto__属性,这个属性指向实例化该实例的构造函数的原型对象(prototype). proterty:这个方法是对象的属性 ...
- Spring Boot 简单入门
添加相关依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http ...
- Introduction Sockets to Programming in C using TCP/IP
Introduction Computer Network: hosts, routers, communication channels Hosts run applications Routers ...
- Golang之实现一个负载均衡算法(随机,轮询)
代码记录 程序结构目录 --------程序包 package balance type Balancer interface { DoBalance([]*Instance, ...string) ...
- 前端基础之:JQuery
- Java07
/* 定义一个类Demo,其中定义一个求两个数据和的方法, 定义一个测试了Test,进行测试. 变量什么时候定义为成员变量: 如果这个变量是用来描述这个类的信息的,那么,该变量就应该定义为成员变量. ...
- webform调用windows服务
准备工作: .电脑->管理->本地用户和组->组->Administrator双击->隶属->添加Network service->确定 .启动windows ...
- Spring boot——logback.xml 配置详解(三)<appender>
阅读目录 1 appender 2 encoder 文章转载自:http://aub.iteye.com/blog/1101260,在此对作者的辛苦表示感谢! 回到顶部 1 appender < ...
- 基于swoole搭建聊天室程序
1. 创建websocket服务器 swoole从1.7.9版本开始, 内置了websocket服务器功能,我们只需几行简单的PHP代码,就可以创建出一个异步非阻塞多进程的WebSocket服务器. ...
- Freedom DownTime
Storyline Computer hackers are being portrayed as the newest brand of terrorists. This is a story of ...