What Kind of Friends Are You?


Time Limit: 1 Second      Memory Limit: 65536 KB

Japari Park is a large zoo home to extant species, endangered species, extinct species, cryptids and some legendary creatures. Due to a mysterious substance known as Sandstar, all the animals have become anthropomorphized into girls known as Friends.

Kaban is a young girl who finds herself in Japari Park with no memory of who she was or where she came from. Shy yet resourceful, she travels through Japari Park along with Serval to find out her identity while encountering more Friends along the way, and eventually discovers that she is a human.

However, Kaban soon finds that it's also important to identify other Friends. Her friend, Serval, enlightens Kaban that she can use some questions whose expected answers are either "yes" or "no" to identitfy a kind of Friends.

To be more specific, there are n Friends need to be identified. Kaban will ask each of them q same questions and collect their answers. For each question, she also gets a full list of animals' names that will give a "yes" answer to that question (and those animals who are not in the list will give a "no" answer to that question), so it's possible to determine the name of a Friends by combining the answers and the lists together.

But the work is too heavy for Kaban. Can you help her to finish it?

Input

There are multiple test cases. The first line of the input is an integer T (1 ≤ T ≤ 100), indicating the number of test cases. Then T test cases follow.

The first line of each test case contains two integers n (1 ≤ n ≤ 100) and q (1 ≤ q ≤ 21), indicating the number of Friends need to be identified and the number of questions.

The next line contains an integer c (1 ≤ c ≤ 200) followed by c strings p1p2, ... , pc (1 ≤ |pi| ≤ 20), indicating all known names of Friends.

For the next q lines, the i-th line contains an integer mi (0 ≤ mi ≤ c) followed by mi strings si, 1si, 2, ... , simi (1 ≤ |sij| ≤ 20), indicating the number of Friends and their names, who will give a "yes" answer to the i-th question. It's guaranteed that all the names appear in the known names of Friends.

For the following n lines, the i-th line contains q integers ai, 1ai, 2, ... , aiq (0 ≤ aij ≤ 1), indicating the answer (0 means "no", and 1 means "yes") to the j-th question given by the i-th Friends need to be identified.

It's guaranteed that all the names in the input consist of only uppercase and lowercase English letters.

Output

For each test case output n lines. If Kaban can determine the name of the i-th Friends need to be identified, print the name on the i-th line. Otherwise, print "Let's go to the library!!" (without quotes) on the i-th line instead.

Sample Input

2
3 4
5 Serval Raccoon Fennec Alpaca Moose
4 Serval Raccoon Alpaca Moose
1 Serval
1 Fennec
1 Serval
1 1 0 1
0 0 0 0
1 0 0 0
5 5
11 A B C D E F G H I J K
3 A B K
4 A B D E
5 A B K D E
10 A B K D E F G H I J
4 B D E K
0 0 1 1 1
1 0 1 0 1
1 1 1 1 1
0 0 1 0 1
1 0 1 1 1

Sample Output

Serval
Let's go to the library!!
Let's go to the library!!
Let's go to the library!!
Let's go to the library!!
B
Let's go to the library!!
K

Hint

The explanation for the first sample test case is given as follows:

As Serval is the only known animal who gives a "yes" answer to the 1st, 2nd and 4th question, and gives a "no" answer to the 3rd question, we output "Serval" (without quotes) on the first line.

As no animal is known to give a "no" answer to all the questions, we output "Let's go to the library!!" (without quotes) on the second line.

Both Alpaca and Moose give a "yes" answer to the 1st question, and a "no" answer to the 2nd, 3rd and 4th question. So we can't determine the name of the third Friends need to be identified, and output "Let's go to the library!!" (without quotes) on the third line.

题意:t组数据 n个需要判断的人 q个问题 n个名字  q个问题的询问对象  n个人对q个问题的回答情况 判断能否唯一的确定姓名 可以则输出姓名 否则输出"Let's go to the library!!"

题解:STL

 #include<bits/stdc++.h>
using namespace std;
int t;
int n,q;
int s;
map<string,vector<int> > mp;
map<int,string> st;
int ve[];
char a[];
int main()
{
string str;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
mp.clear();
st.clear();
scanf("%d %d",&n,&q);
scanf("%d",&s);
for(int j=;j<=s;j++){
scanf("%s",a);
str.assign(a);
st[j]=str;
}
for(int k=;k<=q;k++)
{
int ww;
scanf("%d",&ww);
for(int j=;j<=ww;j++)
{
scanf("%s",a);
str.assign(a);
mp[str].push_back(k);
}
}
int exm;
for(int k=;k<=n;k++)
{
int zha=;
for(int j=;j<=q;j++)
{
scanf("%d",&exm);
if(exm==)
ve[zha++]=j;
}
int judge=;
string ans;
for(int e=;e<=s;e++)
{
if(mp[st[e]].size()==zha)
{
int len=zha;
int zong=;
for(int r=;r<len;r++)
{
if(mp[st[e]][r]==ve[r])
zong++;
}
if(zong==len){
judge++;
ans=st[e];
}
}
}
if(judge==)
cout<<ans<<endl;
else
printf("Let's go to the library!!\n");
}
}
return ;
}

The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - C 暴力 STL的更多相关文章

  1. The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - F 贪心+二分

    Heap Partition Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge A sequence S = { ...

  2. ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp

    Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or s ...

  3. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - L Doki Doki Literature Club

    Doki Doki Literature Club Time Limit: 1 Second      Memory Limit: 65536 KB Doki Doki Literature Club ...

  4. 2018浙江省赛(ACM) The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple

    我是铁牌选手 这次比赛非常得爆炸,可以说体验极差,是这辈子自己最脑残的事情之一. 天时,地利,人和一样没有,而且自己早早地就想好了甩锅的套路. 按理说不开K就不会这么惨了啊,而且自己也是毒,不知道段错 ...

  5. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - M Lucky 7

    Lucky 7 Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao has just found a positive integer se ...

  6. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - J CONTINUE...?

    CONTINUE...? Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge DreamGrid has  clas ...

  7. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke

    King of Karaoke Time Limit: 1 Second      Memory Limit: 65536 KB It's Karaoke time! DreamGrid is per ...

  8. The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple -A Peak

    Peak Time Limit: 1 Second      Memory Limit: 65536 KB A sequence of  integers  is called a peak, if ...

  9. ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)

    #include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...

随机推荐

  1. Cube Stacking P0J 1988(加权并查集)

    Description Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes ...

  2. Masha and Bears(翻译+思维)

    Description A family consisting of father bear, mother bear and son bear owns three cars. Father bea ...

  3. LeetCode 48. Rotate Image (C++)

    题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwis ...

  4. “Hello World!”团队第六周的第一次会议

    今天是我们团队“Hello World!”团队第六周召开的第一次会议.博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.Todo List 六.会议照片 七.燃尽图 一.会议时间 ...

  5. 王者荣耀交流协会第一次Scrum立会

    工作照片: scrum master:高远博 时间跨度;2017/10/13 6:04-6:34 地点:一食堂二楼两张桌子旁 立会内容; 昨天的成绩;昨天商议了今天的开会的时间.地点 今天的计划;讨论 ...

  6. 暑假App

    简介 实现了一个计时器APP,程序界面简洁,只有一个时间显示区域和两个图片按钮,一个按钮是开始/暂停,另一个按钮是停止. 功能介绍 一个显示界面,当最小计时单位为0.1秒时,显示为:分钟:秒:0.1秒 ...

  7. 20162320MyOD重做版

    博客说明 由于上次的MyOD.java没有得分,所以这次我重做了这个java,代码是自己完成的,请教了一些同学的思路.故补交一篇博客来说明我对每一步代码的编写的想法以及理解. 代码片段及理解 1.先创 ...

  8. HDU 5269 ZYB loves Xor I Trie树

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5269 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  9. Alpha-7

    前言 失心疯病源7 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 18:30~20:30 通过统计法来得出人车团块的区别和鉴别方法,然而效果并不显著 代码签 ...

  10. 按照事务类型分析 DB2 事物的性能

    概述 事务是数据库系统中的核心概念之一.作为数据库系统的逻辑工作单元(Unit of Work),事务必须具有四个属性,即原子性.一致性.隔离性和持久性(ACID).数据库系统往往通过锁机制保证事务的 ...