Problem A. Poetry Challenge

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100500/attachments

Description

Let’s check another challenge of the IBM ICPC Chill Zone, a poetry challenge. One says a poetry string that starts with an English letter and ends with an English letter, the second should say a poetry string that starts with the same letter that the previous string ended with.
Given the two poetry string sets representing the known strings for each player. Each player can use each of his strings only once. If during the player turn he can not say any string, he loses. Assuming both players play optimally well determine which player wins the game depending on the given two sets.

Input

The first line contains an integer T represent the number of the following test cases. Each test case starts with an integer n the number of strings in the first player set. Each of the next n lines contains a string of the first player set. Then read an integer m, which will be succeeded by m lines describing the strings of the second player. No string in the input will start or finish with a white space, only lowercase letters. The length of each string in the input will not exceed 10,000 letters. 1 ≤ n ≤ 9 1 ≤ m ≤ 9 1 ≤ T ≤ 10

Output

For each test case, print one line saying which player should win if they are so clever to play it perfectly and assuming that each one knows the set of the other player. Discarding quotes, print "Game_i:_player1"to denote the wining of the first player or "Game_i:_player2"to denote the win of the second player where ‘i’ represents the game number starting from 1. Replace the underscores with spaces.

Sample Input

2 3 a poetry string a poetry string starting with a a poetry string ending with a 3 generated word a word ending with b poetry 2 either one or two random string 3 another test case one greatest poetry be the winner

Sample Output

Game 1: player2 Game 2: player1

HINT

题意

从player1开始进行字母接龙游戏,接不下去的输,问最后谁赢了

题解:

转化成点与点相接,dfs.......    感谢小q神的博客

代码

  

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <queue>
  10. #include <typeinfo>
  11. #include <map>
  12. #include <stack>
  13. typedef long long ll;
  14. using namespace std;
  15. inline ll read()
  16. {
  17. ll x=,f=;
  18. char ch=getchar();
  19. while(ch<''||ch>'')
  20. {
  21. if(ch=='-')f=-;
  22. ch=getchar();
  23. }
  24. while(ch>=''&&ch<='')
  25. {
  26. x=x*+ch-'';
  27. ch=getchar();
  28. }
  29. return x*f;
  30. }
  31. //**************************************************************************************
  32. vector<int > e[];
  33. bool vis[];
  34. bool dfs(int x)
  35. {
  36. for(int i=; i<e[x].size(); i++)
  37. {
  38. if(vis[e[x][i]])continue;
  39. vis[e[x][i]]=;
  40. if(!dfs(e[x][i]))
  41. {
  42. vis[e[x][i]]=;
  43. return ;
  44. }
  45. }
  46. return ;
  47. }
  48. int main()
  49. {
  50. int oo=;
  51. int T;
  52. scanf("%d",&T);
  53. while(T--)
  54. {
  55. memset(vis,,sizeof(vis));
  56. for(int i=; i<; i++)
  57. e[i].clear();
  58. int n=read();
  59. char a[];
  60. char s1[][];
  61. char s2[][];
  62. for(int i=; i<=n; i++)
  63. {
  64. gets(s1[i]);
  65.  
  66. }
  67. int m=read();
  68. for(int i=; i<=m; i++)
  69. gets(s2[i]);
  70. for(int i=; i<=n; i++)
  71. { int l=strlen(s1[i]);
  72. for(int j=; j<=m; j++)
  73. {
  74.  
  75. if(s1[i][l-]==s2[j][])
  76. e[i].push_back(j+);
  77. }
  78. }
  79. for(int i=; i<=m; i++)
  80. { int l=strlen(s2[i]);
  81. for(int j=; j<=n; j++)
  82. {
  83.  
  84. if(s2[i][l-]==s1[j][])
  85. e[i+].push_back(j);
  86. }
  87. }
  88. bool flag=false;
  89. for(int i=; i<=n; i++)
  90. {
  91. vis[i]=;
  92. if(!dfs(i))
  93. {
  94. flag=true;
  95. break;
  96. }
  97. vis[i]=;
  98. }
  99. if(flag)
  100. printf("Game %d: player1\n",oo++);
  101. else
  102. printf("Game %d: player2\n",oo++);
  103. }
  104. return ;
  105. }

CodeForces Gym 100500A A. Poetry Challenge DFS的更多相关文章

  1. codeforces Gym 100187J J. Deck Shuffling dfs

    J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  2. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  3. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  4. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  5. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  6. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  7. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  8. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

  9. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

随机推荐

  1. DataGridView设置不自动显示数据库中未绑定的列

    项目中将从数据库查出来的数据绑定到DataGridView,但是不想显示所有的字段.此功能可以通过sql语句控制查出来的字段数目,但是DataGridView有属性可以控制不显示未绑定的数据,从UI层 ...

  2. Mongodb for C# 分组查询

    #region 排序获取集合 static List<BsonDocument> GetPagerWithGroup(string connectionString, string dat ...

  3. Linux 下安装配置 JDK7

    Linux 下安装配置 JDK7 配置环境(debian 7) 自从从Oracle收购Sun近三年来,已经有很多变化.早在8月,甲骨文将“Operating System Distributor Li ...

  4. Java-优秀博客推荐

    一. TCP/IP Socket 兰亭风雨的专栏: http://blog.csdn.net/ns_code 二. NIO 并发编程网-Java NIO系列教程:http://ifeve.com/ch ...

  5. C++中map的一点疑惑...

    int CRuntimePara::getInt(const string& strKey,int iDefault){ map<string,string>::const_ite ...

  6. 寻虫记:BOM头制造的冤案,无故多出空白行

    最近在做的一个网站发生了一个很诡异的BUG: 使用IE浏览页面时,一切都挺正常: 而使用Firefox浏览时,发现某些页面元素之间的距离比预期的要宽很多,HTML元素本身的hight.padding和 ...

  7. tyvj3481 越狱

    描述 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相信房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 输入格式 输入两个整数 ...

  8. Ninth scrum meeting - 2015/11/3

    今天课上老师询问了每个团队的进度,我们发现有好多团队都已经基本完成了, 距离预定的alpha版本开发完成时间也越来越近了,我们的工作也都在有条不紊的进行着.今天又出现了git pull时有冲突的情况, ...

  9. Unity3d Static 静态批处理和动态批处理

    表示物体时静态的,多用于静止不动的物体,此外static有多种,有的用于烘焙,有的用于遮挡剔除 物理效果是rigidbody组件,和这个没关系,用transform.Translate 无法移动,因为 ...

  10. 关于windows程序的学习及思考系列之一

    1.窗口类的注册 a.windows程序中最简单的就是创建一个简单的窗口,而窗口程序的创建是基于窗口类的,窗口类决定了处理窗口消息的过程函数. b.一个窗口类可以用于创建多个窗口,也就是说窗口是窗口类 ...