博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SGU 406 Goggle
阅读量:6758 次
发布时间:2019-06-26

本文共 2948 字,大约阅读时间需要 9 分钟。

406. Goggle

Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard

Everybody knows search engine Goggle. But only advanced users know that it is possible to search number sequences. You can enter a set of numbers and the search engine will find all sequences which contain it. Goggle developers decided to improve the engine. New feature will help you if you know numbers which shouldn't be in the result. These numbers must be entered with the opposite sign. For example, if somebody enters "5 -3 6", the engine will find all the sequences which contain 5 and 6, but do not contain 3.
Help Goggle developers to implement the feature.

Input

The first line of the input will contain two integer numbers n and m (1 ≤ n ≤ 10, 1 ≤ m ≤ 10), where n is the number of sequences in Goggle database and m is the number of queries. Following n lines describe sequences in the Goggle database. The first integer k in each line is the length of the sequence (1 ≤ k ≤ 10). Next k numbers are the sequence elements. All of them are integers between 1 and 100, inclusive. Following m lines describe queries. The first integer l of each line is the numbers in query (1 ≤ l ≤ 10). Next l numbers bi are the sequence elements (1 ≤ |bi| ≤ 100, bi ≠ 0). These numbers have different absolute values.

Output

For each query print t — the number of found sequences on a separate line. Each of the next t lines should contain found sequence. The relative order of sequences should be preserved (in compliance with the input). The order of numbers in sequences should not change (in compliance with the input). Write sequences in format as they were given in the input.

Example(s)
sample input
sample output
3 56 1 2 3 1 2 34 3 2 4 52 4 23 1 2 32 3 23 2 -1 32 4 -22 4 5
16 1 2 3 1 2 326 1 2 3 1 2 34 3 2 4 514 3 2 4 5014 3 2 4 5
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #define maxn 20015 using namespace std;16 int len[maxn],a[maxn],b[maxn][maxn],hh[maxn][maxn],res[maxn];17 int tot,n,m,lend,flag;18 int main(){19 //freopen("test.in","r",stdin);20 scanf("%d%d",&n,&m);21 memset(hh,0,sizeof(hh));22 for(int i=1;i<=n;i++){23 scanf("%d",&len[i]);24 for(int j=1;j<=len[i];j++) scanf("%d",&b[i][j]),hh[i][b[i][j]]++;25 }26 for(int i=1;i<=m;i++){27 tot=0;28 scanf("%d",&lend);29 for(int j=1;j<=lend;j++) scanf("%d",&a[j]);30 for(int j=1;j<=n;j++){31 flag=1;32 for(int k=1;k<=lend;k++)33 if((a[k]>0&&hh[j][a[k]])||(a[k]<0&&!hh[j][-a[k]])) continue;34 else flag=0;35 if(flag) res[++tot]=j;36 37 }38 printf("%d\n",tot);39 for(int j=1;j<=tot;j++){40 printf("%d",len[res[j]]);41 for(int k=1;k<=len[res[j]];k++) printf(" %d",b[res[j]][k]);42 printf("\n");43 }44 }45 46 }
View Code

 

转载地址:http://lafeo.baihongyu.com/

你可能感兴趣的文章
打开office提示还有几天过期的处理办法
查看>>
leetcode 140 单词拆分2 word break II
查看>>
程序常用的设计技巧
查看>>
jdk源码阅读笔记之java集合框架(四)(LinkedList)
查看>>
Corporative Network UVALive - 3027 (并查集)
查看>>
JS实现单选按钮回显时页面效果出现,但选中单选框的值为空
查看>>
tomcat启动报错The JRE could not be found.Edit the server and change the JRE location
查看>>
dispatchers 设置
查看>>
JQuery
查看>>
转移python
查看>>
OpenCV---resize
查看>>
聊聊CSS postproccessors
查看>>
T-SQL:GO语句和批处理
查看>>
算法参考资料(更新)
查看>>
Poj 水题
查看>>
php中关于mysqli和mysql区别的一些知识点分析
查看>>
Fiddler的基本介绍
查看>>
Mysql On Mac OS: Remove & Install
查看>>
莫烦大大keras学习Mnist识别(4)-----RNN
查看>>
STL之string插入
查看>>