题目链接

:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5592

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 p1, p2, ... , pc (1 ≤ |pi| ≤ 20), indicating all known names of Friends.

For the next q lines, the i-th line contains an integer mi (0 ≤ mic) followed by mi strings si, 1, si, 2, ... , si, mi (1 ≤ |si, j| ≤ 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, 1, ai, 2, ... , ai, q (0 ≤ ai, j ≤ 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.

  1 /*
  2 问题
  3 第一个表输入每个人给出每个问题回答,第一个集合中出现的是1,没有出现的是0
  4 第二个表输入需要识别的每个人对于每个问题的回答,结合两张表,看是否存在唯一一个人,
  5 是输出他的名字,否输出Let's go to the library!!
  6
  7 解题思路
  8 先将每个人根据名字进行编号,使用map映照容器更方便,然后制作两张表,两重循环查询即可。
  9 */
 10 #include<cstdio>
 11 #include<cstring>
 12 #include<string>
 13 #include<iostream>
 14 #include<map>
 15 using namespace std;
 16
 17 void f(int h);
 18 int n,q,c;
 19 map<string,int> namelist;
 20 int list1[200][30],list2[200][30];
 21 int OK(int x[],int y[]);
 22
 23 int main()
 24 {
 25     int t,i,j,k,m;
 26     string sname;
 27     char name[30];
 28     scanf("%d",&t);
 29     while(t--){
 30         scanf("%d%d%d",&n,&q,&c);
 31         namelist.clear();
 32         for(i=0;i<c;i++){
 33             scanf("%s",name);
 34             sname=name;
 35             namelist[sname]=i;
 36         }
 37
 38         memset(list1,0,sizeof(int)*200*30);
 39         for(i=0;i<q;i++){
 40             scanf("%d",&m);
 41             for(j=0;j<m;j++){
 42                 scanf("%s",name);
 43                 sname=name;
 44                 list1[ namelist[sname] ][i]=1;
 45             }
 46         }
 47
 48         /*for(i=0;i<c;i++){
 49             for(j=0;j<q;j++){
 50                 printf("#%d ",list1[i][j]);
 51             }
 52             printf("\n");
 53         }*/
 54
 55         for(i=0;i<n;i++){
 56             for(j=0;j<q;j++){
 57                 scanf("%d",&list2[i][j]);
 58             }
 59         }
 60
 61         /*for(i=0;i<n;i++){
 62             for(j=0;j<q;j++){
 63                 printf("@%d ",list2[i][j]);
 64             }
 65             printf("\n");
 66         }*/
 67
 68         for(i=0;i<n;i++){
 69             f(i);
 70         }
 71     }
 72     return 0;
 73 }
 74
 75 int OK(int x[],int y[])
 76 {
 77     int i;
 78     for(i=0;i<q;i++){
 79         if(x[i] != y[i])
 80             return 0;
 81     }
 82     return 1;
 83 }
 84
 85 void f(int h)
 86 {
 87     int i,j,k;
 88     int cou=0,z=0;
 89     for(i=0;i<c;i++){
 90         if(OK(list1[i],list2[h])){
 91             z=i;
 92             cou++;
 93         }
 94     }
 95
 96     if(cou == 1){
 97         map<string,int>::iterator it;
 98         for(it=namelist.begin();it != namelist.end();it++){
 99             if((*it). second == z){
100                 cout<<(*it).first<<endl;
101                 break;
102             }
103         }
104     }
105     else
106         printf("Let's go to the library!!\n");
107 }

转载于:https://www.cnblogs.com/wenzhixin/p/9001951.html

ZOJ 3960 What Kind of Friends Are You?(读题+思维)相关推荐

  1. kuangbin 最小生成树专题 - ZOJ - 1586 QS Network (朴素 Prim算法 模板题)

    kuangbin 最小生成树专题 - ZOJ - 1586 QS Network (朴素 Prim算法 模板题) 总题单 week 3 [kuangbin带你飞] 题单 最小生成树 + 线段树 Cli ...

  2. POJ ZOJ题目分类

    POJ,ZOJ题目分类(多篇整合版,分类很细致,全面) 标签: 题目分类POJ整理 2015-04-18 14:44 1672人阅读 评论(0) 收藏 举报 本文章已收录于: 分类: ACM资料(5) ...

  3. POJ,ZOJ题目分类(多篇整合版,分类很细致,全面)

    水题: 3299,2159,2739,1083,2262,1503,3006,2255,3094 初级: 一.基本算法:        (1)枚举 (1753,2965)       (2)贪心(13 ...

  4. poj 3666 Making the Grade zoj 3512 Financial Fraud 左偏树 or dp

    //poj 3666 //分析:只是在2005年集训队论文黄源河提到的题目上略微有一点点变化 1 #include"iostream" 2 #include"cstdio ...

  5. NOIP 好题推荐(DP+搜索+图论)POJ ZOJ

    NOIP好题推荐(DP+搜索+图论)POJ ZOJ 1370 Gossiping (数论->模线性方程有无解的判断)+(图论->DFS)  1090 Chain ->格雷码和二进制码 ...

  6. HZNU Training 4 for Zhejiang Provincial Collegiate Programming Contest 2019

    今日这场比赛我们准备的题比较全面,二分+数论+最短路+计算几何+dp+思维+签到题等.有较难的防AK题,也有简单的签到题.为大家准备了一份题解和AC代码. A - Meeting with Alien ...

  7. 刷了几千道算法题,我私藏的刷题网站都在这里了

    作者 | Rocky0429 来源 | Python空间(ID: Devtogether) 遥想当年,机缘巧合入了 ACM 的坑,周边巨擘林立,从此过上了"天天被虐似死狗"的生活. ...

  8. 算法竞赛注意事项(废话)

    更新一下: 1.刷水题 2.比赛时不要盲目交题 3.Enjoy the game 关于输入输出: 关闭同步 1 ios_base::sync_with_stdio(0); 2 cin.tie(0); ...

  9. 阿里云专家穆轩的《杭州九年程序员之“修炼”手册》

    对于一个从未到过南方的内蒙汉子来说,北京的大学一直是中学时憧憬的殿堂,而离家上千公里浙江大学,则是从来没有考虑过的地方.机缘巧合之下,被一位年近七旬的浙大老师说服,我自此开始了南下"修炼&q ...

最新文章

  1. AD5933使用外部时钟获得更低的分析频率
  2. Hadoop2配置详解
  3. MySQL配置文件my.cnf中文详解
  4. C 中 static 的常见作用
  5. 阿里云 Serverless Kubernetes 的落地实践分享
  6. UVa-227-谜题
  7. 网页 js 获取DPI pxTomm
  8. 学生成绩表mysql_mysql 学生成绩表例题
  9. omni rpc python生成地址_python编辑图形界面单一功能MAC随机地址生成
  10. Android 两种方式实现类似水波扩散效果
  11. 常见字符编码详解ANSI,UTF-8,UCS,GBK,GB2312,BIG5
  12. APUE---chap8(进程控制)---8.11(setuid/getuid)
  13. C#扫雷外挂辅助工具
  14. linux打开xml文件,xml文件扩展名,xml文件怎么打开?
  15. SpringBoot整合Flyway
  16. 树的递归与非递归遍历算法
  17. 面试季,各大厂真实面试题拿走不谢
  18. html游戏让目标人物移动,用仿ActionScript的语法来编写html5——第三篇,鼠标事件与游戏人物移动...
  19. 数据的处理之工具推荐(MATLAB、Python、Panoply、CDO、NCL)
  20. android手机几个目录的介绍:/system/app; /system/vender;/data/app;/data/dalvik-cache;/mnt/asec;/mnt/secure

热门文章

  1. 动态链接库的路径及依赖
  2. 今天的样子,绝非偶然
  3. 女朋友过生日,男子买了一条项链,女友:值不了多少钱
  4. VMware部分产品
  5. 一个瑞典游戏工作室决定离开索尼,之前和之后都发生了什么?
  6. socket局域网聊天demo
  7. 湖北大学计算机考研参考书,湖北大学2018考研专业课参考书
  8. 2019-12-17
  9. 丘成桐:赋比兴、境界与数学
  10. MDT2008部署杂谈2——简介