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 & ...
随机推荐
- 27.集成EFCore配置Client和API
copy链接字符串,这是一个官方的字符串,直接复制过来,放在上面. 添加包的引用 引入IdentityServer4.EntityFramework的命名空间 主要是这个地方初始化我们的数据库 Ope ...
- 自己在项目中写的一个Jquery插件和Jquery tab 功能
后台查询结果 PDFSearchResult实体类: [DataContract(Name = "PDFSearchResult")] public class PDFSearch ...
- 2. nmap扫描神器总结
-----------------nmap(选项)(参数)------------------O:激活操作探测: -P0:值进行扫描,不ping主机: -PT:是同TCP的ping: -sV:探测服务 ...
- Django 中ORM 的使用
一:Django 中 orm 的使用 1:手动新建一个数据库 2 :告诉Django连接哪个数据库 settings.py里配置数据库连接信息: #数据库相关的配置项 DATABASES ={ 'de ...
- 数据库路由中间件MyCat - 源代码篇(6)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3. 连接模块 3.3 AbstractConnection: 3.3.2 NIOHandler NIOHa ...
- 聊聊心跳机制及netty心跳实现
我们在使用netty的时候会使用一个参数,ChannelOption.SO_KEEPALIVE为true, 设置好了之后再Linux系统才会对keepalive生效,但是linux里边需要配置几个参数 ...
- 51nod 1086【背包·DP】
思路: 如果体积乘以数量>=W,那么直接用完全背包模型.如果不到的话,用二进制优化就好了. 基础题,感觉这样写很优雅?回去睡觉. #include <bits/stdc++.h> u ...
- js基础(创建标签)
创建标签 var divBox1 = document.getElementById('box1'); var p = document.createElement('p'); p.innerHTML ...
- 719D(树形dp)
题目链接:http://codeforces.com/contest/791/problem/D 题意:给出一棵树,每两个点之间的距离为1,一步最多可以走距离 k,问要将任意两个点之间的路径都走一遍, ...
- IT兄弟连 JavaWeb教程 经典案例
案例需求:编写一个jsp servlet程序,在login.jsp发起login.do登录请求,当输入的用户名是abc密码是123时,则判断是登录成功,其它暂时认为是登录失败.当用户登录成功时,将用户 ...