A String Game

 
Problem code: ASTRGAME
 
 

All submissions for this problem are available.

Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substring that exists in the dictionary. The dictionary consists of N words.

Of course, the player that can't erase any substring in his turn loses the game, and the other player is declared the winner.

Note that after a substring R is erased, the remaining substring becomes separated, i.e. they cannot erase a word that occurs partially to the left of R and partially to the right of R.

Determine the winner of the game, assuming that both players play optimally.

Input

The first line contains a single integer T, the number of test cases. T test cases follow. The first line of each testcase contains a string S, the string Tracy writes on the whiteboard. The next line contains a single integer N. N lines follow. The i-th line contains a single string wi, the i-th word in the dictionary.

Output

For each test case, output a single line containing the name of the winner of the game.

Example

Input:
3
codechef
2
code
chef
foo
1
bar
mississippi
4
ssissi
mippi
mi
ppi Output:
Tracy
Tracy
Teddy

Constraints

  • 1 <= T <= 5
  • 1 <= N <= 30
  • 1 <= |S| <= 30
  • 1 <= |wi| <= 30
  • S and wi contain only characters 'a'-'z'

SG博弈

#include <bits/stdc++.h>
using namespace std ;
const int N = ;
bool check[N][N] ;
int sg[N][N] , vis[] ;
string s , word ;
int main() {
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
int _ , n ; cin >> _ ;
while( _-- ) {
cin >> s ; int slen = s.length() ;
memset( check , false , sizeof check );
memset( vis , , sizeof vis);
memset( sg , , sizeof sg );
cin >> n ;
for( int i = ; i < n ; ++i ) {
cin >> word ; int wlen = word.length() ;
for( int j = ; j + wlen <= s.length() ; ++j ) {
if( word == s.substr( j , wlen ) )
check[j][j+wlen] = true ;
}
}
int cnt = ;
for( int len = ; len <= slen ; ++len ) {
for( int be = ; be < slen ; ++be ) {
cnt++ ; int ed = be + len ; if( ed > slen ) continue ;
for( int i = be ; i < ed ; ++i ){
for( int j = i + ; j <= ed ; ++j ) if( check[i][j] ){
vis[ sg[be][i]^sg[j][ed] ] = cnt ;
}
}
int z = ;
while( vis[z] == cnt ) z++;
sg[be][ed] = z ;
}
}
if( sg[][slen] ) cout << "Teddy" << endl ;
else cout << "Tracy" << endl ; }
}

CodeChef A String Game(SG)的更多相关文章

  1. hdu 1809 求SG函数

    A New Tetris Game(2) Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. 微信公众号开发(一)--验证服务器地址的Java实现

    现在主流上都用php写微信公众号后台,其实作为后端语言之一的java也可以实现. 这篇文章将对验证服务器地址这一步做出实现. 参考资料:1.慕课网-<初识java微信公众号开发>,2.微信 ...

  3. 《用delphi开发共享软件》-15.2桌面提示器

    打开一个配置文件: 打开一个配置文件 操作TStringGrid Procedure EmptyGrid(Var sg:TStringGrid); Var i:Integer; begin do sg ...

  4. Java SE 8 流库

    1. 流的作用 通过使用流,说明想要完成什么任务,而不是说明如何去实现它,将操作的调度留给具体实现去解决: 实例:假如我们想要计算某个属性的平均值,那么我们就可以指定数据源和属性,然后,流库就可以对计 ...

  5. 通过Visualizing Representations来理解Deep Learning、Neural network、以及输入样本自身的高维空间结构

    catalogue . 引言 . Neural Networks Transform Space - 神经网络内部的空间结构 . Understand the data itself by visua ...

  6. Java SE 8 流库(一)

    1. 流的作用 通过使用流,说明想要完成什么任务,而不是说明如何去实现它,将操作的调度留给具体实现去解决: 实例:假如我们想要计算某个属性的平均值,那么我们就可以指定数据源和属性,然后,流库就可以对计 ...

  7. 把list(对象)集合中的(某个属性),放到数组中。

    List<SpecialguardInfo> list=specialguardOrderService.findfreeSg(date1,date2);//得到list对象集合 Stri ...

  8. 2019的hdu暑假作业(欢迎纠错)

    1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...

  9. java - day019 - 反射

    网络程序,难点在线程 反射 reflect 实用 类对象 来执行反射操作 反射获得一个类的定义信息 反射创建对象 反射调用成员变量, 方法 方法 获得类对象的三种方式 A.class Class.fo ...

随机推荐

  1. more - 在显示器上阅读文件的过滤器

    总览 (SYNOPSIS) more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ] 描述 (DESCRIPTION) More 是 ...

  2. 关于conda-新手必读

    一.管理conda 通过anaconda来安装python及python包,让你不必关心系统是否安装了一些依赖,如zlib等等,anaconda已经集成了这些依赖,可以方便的安装python 下载请点 ...

  3. VS2012 改C# 模版

    原始文件位置: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplatesCache\CSharp\Co ...

  4. BZOJ 5046 分糖果游戏

    网页崩溃了 心态也崩溃了 MD劳资写了那么多 题意: 有a,b两个人分糖,每个人都有一个能量值.每个人每一轮可以选择进行两种操作: 1.取走最左边的糖果,补充相应的能量值并获取相应的美味度. 2.跳过 ...

  5. Java数组重修,猜数小游戏改进和打印正三角形

    数组重修,猜数小游戏 要求:从键盘输入一个数,判断数组是否包含此数,运用随机数 我们可能会这样写 import java.util.Random; import java.util.Scanner; ...

  6. 028:with标签使用详解

    with标签使用详解: 1.在模板中享用使用变量,可以通过  with  语句实现: 2.with  有两种用法,具体情况如下 ( 包括注意事项 ) : index.html: <p>wi ...

  7. php substr()函数 语法

    php substr()函数 语法 作用:截取字符串 语法:substr(string,start,length)大理石平台 参数: 参数 描述 string 必需.规定要返回其中一部分的字符串. s ...

  8. 2017ICPC沈阳网络赛 HDU 6201 -- transaction transaction transaction(树上dp)

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  9. CSS实现回到顶部图片hover后改变效果

    任何网站中回到顶部元素不可缺少,一般为了实现交互效果,都会在鼠标hover后元素样式有所改变.今天这个实例便是采用CSS中的transform知识实现. hover: <!DOCTYPE htm ...

  10. 6 October

    P1514 引水入城 题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 \(N\) 行 \(\times M\) 列的矩形,如上图所示, ...