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 & ...
随机推荐
- 自定义TabWidget
在开发过程中,默认的TabWidget不能满足我们对于UI的要求并且没有足够的属性工我们去修改,这个时候能够自定义TabWidget是非常必要的.自定义TabWidget组要运用的是TabSpec.s ...
- 洛谷P3382 【模板】三分法(三分找凹凸点)
P3382 [模板]三分法 题目描述 如题,给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 输入输出格式 输入格式: 第一行一次包含一个 ...
- Guid string 转换
System.Guid.NewGuid().ToString(); //GUID带-分割// db1b98e9-6f93-41aa-84f8-5eb773e93d67System.Guid.NewGu ...
- 使用PowerDesigner创建物理模型并生成SQL语句在MySQL中生成表
我使用的PowerDesigner的版本为16.5,创建物理模型后,使用PowerDesigner生成的SQL语句,在MySQL中创建表. 1. 打开Power Designer软件,在弹出的欢迎对话 ...
- 51nod1103(抽屉原理)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1103 题意:中文题诶- 思路:抽屉原理 对于两个数a, b, ...
- 洛谷P2687 [USACO4.3]逢低吸纳Buy Low, Buy Lower
P2687 [USACO4.3]逢低吸纳Buy Low, Buy Lower 题目描述 “逢低吸纳”是炒股的一条成功秘诀.如果你想成为一个成功的投资者,就要遵守这条秘诀: "逢低吸纳,越低越 ...
- IT兄弟连 JavaWeb教程 使用AJAX发送POST请求并获取响应
POST请求用于向服务器发送应该被保存的数据,因此POST请求天然比GET请求多需要一份需要被保存的数据.那么这些数据应该放在何处呢?毕竟,我们的open()方法接收的三个参数都没有合适的位置. 答案 ...
- 道阻且长 莫失本心(我的OI之旅
道阻且长 莫失本心 今天午睡醒来,发现自己发烧了.尽管穿的很厚,尽管今天的阳光如此明媚.身体还是由内而外地散发着冷意. 期末考已经结束了,接下来又是艰难而难忘的奥赛训练.(要到春节才能放假了 ...
- 笔记-JavaWeb学习之旅14
JSTL:JavaServer Pages Tag Library JSP标准标签库 if标签 <%@ page import="java.util.ArrayList" % ...
- jquery jtemplates.js模板渲染引擎的详细用法第二篇
jquery jtemplates.js模板渲染引擎的详细用法第二篇 关于jtemplates.js的用法在第一篇中已经讲过了,这里就直接上代码,不同之处是绑定模板的方式,这里讲模板的数据专门写一个t ...