codeforce Gym 100500A Poetry Challenge(博弈,暴搜)
题解:状态压缩之后,暴力dfs,如果有一个选择,能让对手必败,那么就是必胜态,能转移到的状态都是对手的必胜态,或者无法转移,就是必败态。
总算是过了,TLE是因为状态没判重。
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
//#define local const int maxn = ; char str[maxn];
int n,m;
struct Node
{
char h,r;
}; Node P[][];
bool G[][][];
bool vis[<<]; bool dfs(int p,int u,int sta)
{
for(int v = ,sz = p?m:n; v < sz; v++) if(G[p][u][v]&&!((sta>>(v+p*))&)) {
int newsta = sta|(<<(v+p*));
if(vis[newsta]) continue;
vis[newsta] = ;
if(!dfs(p^,v,newsta)) return true;
vis[newsta] = ;
}
return false;
}
int main()
{
#ifdef local
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif // local
int T;
scanf("%d",&T);
for(int k = ; k <= T; k++){
scanf("%d",&n); getchar();
for(int i = ; i < n; i++){
gets(str);
P[][i].h = *str;
P[][i].r = str[strlen(str)-];
}
scanf("%d",&m); getchar();
for(int i = ; i < m; i++){
gets(str);
P[][i].h = *str;
P[][i].r = str[strlen(str)-];
} memset(G,,sizeof(G));
for(int i = ; i < n; i++){
for(int j = ; j < m; j++){
if(P[][i].r == P[][j].h) {
G[][i][j] = ;
}
if(P[][j].r == P[][i].h) {
G[][j][i] = ;
}
}
}
memset(vis,,sizeof(vis));
bool p1Win = false;
for(int i = ; i < n; i++){
if(!dfs(,i,<<i)) { p1Win = true; break; };
}
printf("Game %d: player%d\n",k,p1Win?:); }
return ;
}
codeforce Gym 100500A Poetry Challenge(博弈,暴搜)的更多相关文章
- CodeForces Gym 100500A A. Poetry Challenge DFS
Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜
3033: 太鼓达人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 204 Solved: 154[Submit][Status][Discuss] ...
- c++20701除法(刘汝佳1、2册第七章,暴搜解决)
20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 输入正整数n,按从小到大的顺序输出所有 ...
- Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜
题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- Sicily1317-Sudoku-位运算暴搜
最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...
- codeforces 339C Xenia and Weights(dp或暴搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Xenia and Weights Xenia has a set of weig ...
- Usaco 2.3 Zero Sums(回溯DFS)--暴搜
Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...
- HDU4403(暴搜)
A very hard Aoshu problem Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
随机推荐
- Oracle SQL调优之分区表
目录 一.分区表简介 二.分区表优势 三.分区表分类 3.1 范围分区 3.2 列表分区 3.3 散列分区 3.4 组合分区 四.分区相关操作 五.分区相关查询 附录:分区表索引失效的操作 一.分区表 ...
- 2010辽宁省赛G(佩尔方程)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...
- AcEdCommandStack 输出所有命令
; AcEdCommandIterator* iter = nullptr; for (iter = acedRegCmds->iterator(); !iter->done(); ite ...
- bzoj5492:[Hnoi2019]校园旅行
传送门 %%%myy 考虑30分做法:暴力bfs,\(f[i][j]\)表示\(i\)到\(j\)可以形成回文串 然而为什么我场上只想到了70分做法,完全没想到30分怎么写.. 100分: 考虑缩边, ...
- 第一个Three.js程序——动手写一个简单的场景
三维场景基本要素: 步骤: 代码: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- IOS 打包提示 No iTunes Connect access for the team
1.可以在提示页直接点击 Manage Accounts按钮,进去页面后,选择开发者账号点减号删除:(或者在Xcode中直接按command+键进入,选择accounts,选中账号按-键删除) 2.完 ...
- css 样式计算器
css3有个计算器 calc() div { width:-webkit-calc(100% - 100px);注意-两边要有空格 width:-moz-calc(100% - 100px); wid ...
- 10.使用子查询 ---SQL
利用子查询进行过滤 普通查询: SELECT order_num FROM OrderItems WHERE prod_id = 'RGAN01'; 输出▼ order_num ----------- ...
- Vue实例生命周期+vueRoter
Vue实例生命周期 vue生命周期之beforeCreate 实例创建之前除标签外,所有的vue需要的数据,事件都不存在 vue生命周期之created 实例创建之后,data和事件已经被解析到,el ...
- HDU6442(二项式)
要点 懒得打公式了,题解 把题目要求的复杂公式化简成熟悉的东西,一是看穿前面加个\(n!\)化为\(C_n^i,i为奇数\):二是将奇数的条件去掉的数学技巧. 形为\({(a + b\sqrt{B}) ...