题解:状态压缩之后,暴力dfs,如果有一个选择,能让对手必败,那么就是必胜态,能转移到的状态都是对手的必胜态,或者无法转移,就是必败态。

总算是过了,TLE是因为状态没判重。

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<vector>
  4. #include<map>
  5. #include<set>
  6. #include<algorithm>
  7. #include<iostream>
  8. #include<cstring>
  9. using namespace std;
  10. typedef long long ll;
  11. //#define local
  12.  
  13. const int maxn = ;
  14.  
  15. char str[maxn];
  16. int n,m;
  17. struct Node
  18. {
  19. char h,r;
  20. };
  21.  
  22. Node P[][];
  23. bool G[][][];
  24. bool vis[<<];
  25.  
  26. bool dfs(int p,int u,int sta)
  27. {
  28. for(int v = ,sz = p?m:n; v < sz; v++) if(G[p][u][v]&&!((sta>>(v+p*))&)) {
  29. int newsta = sta|(<<(v+p*));
  30. if(vis[newsta]) continue;
  31. vis[newsta] = ;
  32. if(!dfs(p^,v,newsta)) return true;
  33. vis[newsta] = ;
  34. }
  35. return false;
  36. }
  37. int main()
  38. {
  39. #ifdef local
  40. freopen("in.txt","r",stdin);
  41. // freopen("out.txt","w",stdout);
  42. #endif // local
  43. int T;
  44. scanf("%d",&T);
  45. for(int k = ; k <= T; k++){
  46. scanf("%d",&n); getchar();
  47. for(int i = ; i < n; i++){
  48. gets(str);
  49. P[][i].h = *str;
  50. P[][i].r = str[strlen(str)-];
  51. }
  52. scanf("%d",&m); getchar();
  53. for(int i = ; i < m; i++){
  54. gets(str);
  55. P[][i].h = *str;
  56. P[][i].r = str[strlen(str)-];
  57. }
  58.  
  59. memset(G,,sizeof(G));
  60. for(int i = ; i < n; i++){
  61. for(int j = ; j < m; j++){
  62. if(P[][i].r == P[][j].h) {
  63. G[][i][j] = ;
  64. }
  65. if(P[][j].r == P[][i].h) {
  66. G[][j][i] = ;
  67. }
  68. }
  69. }
  70. memset(vis,,sizeof(vis));
  71. bool p1Win = false;
  72. for(int i = ; i < n; i++){
  73. if(!dfs(,i,<<i)) { p1Win = true; break; };
  74. }
  75. printf("Game %d: player%d\n",k,p1Win?:);
  76.  
  77. }
  78. return ;
  79. }

codeforce Gym 100500A Poetry Challenge(博弈,暴搜)的更多相关文章

  1. CodeForces Gym 100500A A. Poetry Challenge DFS

    Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  2. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  3. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  4. 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 ...

  5. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  6. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  7. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  8. 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 ... ...

  9. HDU4403(暴搜)

    A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

随机推荐

  1. 27.集成EFCore配置Client和API

    copy链接字符串,这是一个官方的字符串,直接复制过来,放在上面. 添加包的引用 引入IdentityServer4.EntityFramework的命名空间 主要是这个地方初始化我们的数据库 Ope ...

  2. 自己在项目中写的一个Jquery插件和Jquery tab 功能

    后台查询结果 PDFSearchResult实体类: [DataContract(Name = "PDFSearchResult")] public class PDFSearch ...

  3. 2. nmap扫描神器总结

    -----------------nmap(选项)(参数)------------------O:激活操作探测: -P0:值进行扫描,不ping主机: -PT:是同TCP的ping: -sV:探测服务 ...

  4. Django 中ORM 的使用

    一:Django 中 orm 的使用 1:手动新建一个数据库 2 :告诉Django连接哪个数据库 settings.py里配置数据库连接信息: #数据库相关的配置项 DATABASES ={ 'de ...

  5. 数据库路由中间件MyCat - 源代码篇(6)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 3. 连接模块 3.3 AbstractConnection: 3.3.2 NIOHandler NIOHa ...

  6. 聊聊心跳机制及netty心跳实现

    我们在使用netty的时候会使用一个参数,ChannelOption.SO_KEEPALIVE为true, 设置好了之后再Linux系统才会对keepalive生效,但是linux里边需要配置几个参数 ...

  7. 51nod 1086【背包·DP】

    思路: 如果体积乘以数量>=W,那么直接用完全背包模型.如果不到的话,用二进制优化就好了. 基础题,感觉这样写很优雅?回去睡觉. #include <bits/stdc++.h> u ...

  8. js基础(创建标签)

    创建标签 var divBox1 = document.getElementById('box1'); var p = document.createElement('p'); p.innerHTML ...

  9. 719D(树形dp)

    题目链接:http://codeforces.com/contest/791/problem/D 题意:给出一棵树,每两个点之间的距离为1,一步最多可以走距离 k,问要将任意两个点之间的路径都走一遍, ...

  10. IT兄弟连 JavaWeb教程 经典案例

    案例需求:编写一个jsp servlet程序,在login.jsp发起login.do登录请求,当输入的用户名是abc密码是123时,则判断是登录成功,其它暂时认为是登录失败.当用户登录成功时,将用户 ...