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 ...
随机推荐
- 基于HALCON的双目立体视觉系统实现
双目立体视觉是机器视觉的一种重要形式,它是基于视差原理并由多幅图像获取物体三维几何信息的方法.双目立体视觉系统一般由双摄像机从不同角度同时获得被测物的两幅数字图像,或由单摄像机在不同时刻从不同角度获得 ...
- 7.25 10figting!
TEXT 88 European utilities欧洲公用事业 Power struggles 能源之争(陈继龙编译) Nov 30th 2006 From The Economist print ...
- Kafka学习总结
Kafka学习总结 参考资料: 1.http://kafka.apachecn.org/, kafka官方文档 2.https://www.cnblogs.com/likehua/p/3999538. ...
- Layer Comps
[What is Layer Comps] Designers often create multiple compositions(comps) of a page layout to show c ...
- 因式分解 · Factor Combinations
[抄题]: 给出 n = 8 返回 [[2,2,2],[2,4]] // 8 = 2 x 2 x 2 = 2 x 4 [暴力解法]: 时间分析: 空间分析: [思维问题]: [一句话思路]: 类似于全 ...
- 在 Ruby 中执行 Shell 命令的 6 种方法
我们时常会与操作系统交互或在 Ruby 中执行 Shell 命令.Ruby为我们提供了完成该任务的诸多方法. Exec Kernel#exec 通过执行给定的命令来替换当前进程,例如: $ irb & ...
- Spring boot——logback.xml 配置详解(四)<filter>
阅读目录 1 filter的使用 2 常用的过滤器 文章转载自:http://aub.iteye.com/blog/1101260,在此对作者的辛苦表示感谢! 回到顶部 1 filter的使用 < ...
- SQL group by 分组后,同一组的排序后取第一条
SELECT * FROM( SELECT [SPID] ,[PH1] ...
- ASIHTTPRequest-Cookie的使用[转]
ASIHTTPRequest允许你使用全局存储来和所有使用CFNetwork或者NSURLRequest接口的程序共享cookie. 如果设置useCookiePersistence为YES(默认值) ...
- Linux 基础教程 44-history命令
什么是history 在Linux系统日积月累的使用中,我们会输入很多命令.而在我们想重复上一个命令时,通过使用方向键向上翻就可以查看我们已经输入和使用过的命令.那大家有没有想过这个命令保存在 ...