CodeForces Gym 100500A A. Poetry Challenge DFS
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的更多相关文章
- codeforces Gym 100187J J. Deck Shuffling dfs
J. Deck Shuffling Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...
- Codeforces Gym 101252D&&floyd判圈算法学习笔记
一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...
- Codeforces Gym 101190M Mole Tunnels - 费用流
题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...
- Codeforces Gym 101623A - 动态规划
题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...
- 【Codeforces Gym 100725K】Key Insertion
Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...
- 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 ...
- codeforces gym 100553I
codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...
- CodeForces Gym 100213F Counterfeit Money
CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
随机推荐
- js Float 精度
1.加法 //加法 function add(arg1,arg2){ var r1,r2,m; try{r1=arg1.toString().split(".")[1].lengt ...
- 繁华模拟赛 ljw分雕塑
/* 用f[i][k]表示考虑到第i个雕塑,分成k组,可不可行(这是一个bool类型的数组) 转移: f[i][k]=f[j][k-1],sum[i]-sum[j]合法 */ #include < ...
- Java基础—ClassLoader的理解
##默认的三个类加载器 Java默认是有三个ClassLoader,按层次关系从上到下依次是: - Bootstrap ClassLoader - Ext ClassLoader - System C ...
- 如何用火车头采集当前页面url网址
首先创建一个标签为本文网址,勾选后面的“从网址中采集”. 选择下面的“正则提取”,点击通配符“(?<content>?)”,这样在窗口中就显示为(?<content>[\s\S ...
- 畅通工程再续(MST)
畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Bridge 使用
- ReactiveCocoa入门教程:第一部分
http://www.cocoachina.com/ios/20150123/10994.html 本文翻译自RayWenderlich,原文:ReactiveCocoa Tutorial--The ...
- MyBatis调用存储过程
MySQL存储过程 DROP PROCEDURE IF EXISTS transferMoney; -- 实现转账功能的存储过程 CREATE PROCEDURE transferMoney ( IN ...
- js中的闭包之我理解
闭包是一个比较抽象的概念,尤其是对js新手来说.书上的解释实在是比较晦涩,对我来说也是一样. 但是他也是js能力提升中无法绕过的一环,几乎每次面试必问的问题,因为在回答的时候.你的答案的深度,对术语的 ...
- linux 系统下查看raid信息,以及磁盘信息
有时想知道服务器上有几块磁盘,如果没有做raid,则可以简单使用fdisk -l 就可以看到. 但是做了raid呢,这样就看不出来了.那么如何查看服务器上做了raid? 软件raid:只能通过Lin ...