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神的博客

代码

  

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************************************************************
vector<int > e[];
bool vis[];
bool dfs(int x)
{
for(int i=; i<e[x].size(); i++)
{
if(vis[e[x][i]])continue;
vis[e[x][i]]=;
if(!dfs(e[x][i]))
{
vis[e[x][i]]=;
return ;
}
}
return ;
}
int main()
{
int oo=;
int T;
scanf("%d",&T);
while(T--)
{
memset(vis,,sizeof(vis));
for(int i=; i<; i++)
e[i].clear();
int n=read();
char a[];
char s1[][];
char s2[][];
for(int i=; i<=n; i++)
{
gets(s1[i]); }
int m=read();
for(int i=; i<=m; i++)
gets(s2[i]);
for(int i=; i<=n; i++)
{ int l=strlen(s1[i]);
for(int j=; j<=m; j++)
{ if(s1[i][l-]==s2[j][])
e[i].push_back(j+);
}
}
for(int i=; i<=m; i++)
{ int l=strlen(s2[i]);
for(int j=; j<=n; j++)
{ if(s2[i][l-]==s1[j][])
e[i+].push_back(j);
}
}
bool flag=false;
for(int i=; i<=n; i++)
{
vis[i]=;
if(!dfs(i))
{
flag=true;
break;
}
vis[i]=;
}
if(flag)
printf("Game %d: player1\n",oo++);
else
printf("Game %d: player2\n",oo++);
}
return ;
}

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. Oracle 客户端配置

    nstantclient-basic-nt-12.1.0.1.0\instantclient_12_1下面新建NETWORK文件夹,NETWORK下新建ADMIN文件夹,ADMIN下新建tnsname ...

  2. javafx之CSS初探

    文档:http://www.haogongju.net/art/1807238 javafx中的css元素必须有-fx-前缀. 一.介绍 java8中新增了javafx.css开放了css相关api. ...

  3. .NET深入实战系列--EF到底怎么写过滤条件(转)

    原文来自:http://www.cnblogs.com/yubaolee/p/DynamicLinq.html 对于系统开发来说,按不同字段进行过滤查询是一种常见的需求.在EF中通常的做法是: /// ...

  4. 如何将北京时间批量转为Unix时间?用Excel!

    前面我们说过Unix时间戳转换怎样在Excel批量修改,有些人就想如果有特殊需求,那能不能批量将北京时间批量转成unix时间呢?能!用Excel就可以实现!跟ytkah一起试试吧. 将unix时间戳转 ...

  5. sql导入默认用户解决杰奇cms无法登陆管理员账户问题

    前些天下载杰奇cms来体验一下,从a5下载的杰奇1.8版,不是默认的安装程序,上传文件,手工导入sql数据库,修改了config配置文件,很快就完工了.前台可以展现,除了有些乱码显示之外,想要修改相关 ...

  6. jvm内存模型和内存分配

    1.什么是jvm? (1)jvm是一种用于计算设备的规范,它是一个虚构出来的机器,是通过在实际的计算机上仿真模拟各种功能实现的. (2)jvm包含一套字节码指令集,一组寄存器,一个栈,一个垃圾回收堆和 ...

  7. PowerDesigner15在win7-64位系统下对MySQL反向工程

    由于机器是win64位的,下载的64的connector安装测试成功,但是在powerdesigner中测试连不上,总算在下面这边博友中找到解决方案! http://blog.csdn.net/web ...

  8. [Effective JavaScript 笔记]第48条:避免在枚举期间修改对象

    注册列表示例 一个社交网络有一组成员,每个成员有一个存储其朋友信息的注册列表. function Member(name){ this.name=name; this.friends=[]; } va ...

  9. ReactiveCocoa入门教程:第一部分

    http://www.cocoachina.com/ios/20150123/10994.html 本文翻译自RayWenderlich,原文:ReactiveCocoa Tutorial--The ...

  10. ios 百度地图api 入门

    百度地图api 官方教程: http://developer.baidu.com/map/index.php?title=iossdk 这个非常好, 很适合新手 CLLocationCoordinat ...