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 5
6 1 2 3 1 2 3
4 3 2 4 5
2 4 2
3 1 2 3
2 3 2
3 2 -1 3
2 4 -2
2 4 5
1
6 1 2 3 1 2 3
2
6 1 2 3 1 2 3
4 3 2 4 5
1
4 3 2 4 5
0
1
4 3 2 4 5
 #include<iostream>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include<vector>
#include<map>
#include<deque>
#include<list>
#define maxn 200
using namespace std;
int len[maxn],a[maxn],b[maxn][maxn],hh[maxn][maxn],res[maxn];
int tot,n,m,lend,flag;
int main(){
//freopen("test.in","r",stdin);
scanf("%d%d",&n,&m);
memset(hh,,sizeof(hh));
for(int i=;i<=n;i++){
scanf("%d",&len[i]);
for(int j=;j<=len[i];j++) scanf("%d",&b[i][j]),hh[i][b[i][j]]++;
}
for(int i=;i<=m;i++){
tot=;
scanf("%d",&lend);
for(int j=;j<=lend;j++) scanf("%d",&a[j]);
for(int j=;j<=n;j++){
flag=;
for(int k=;k<=lend;k++)
if((a[k]>&&hh[j][a[k]])||(a[k]<&&!hh[j][-a[k]])) continue;
else flag=;
if(flag) res[++tot]=j; }
printf("%d\n",tot);
for(int j=;j<=tot;j++){
printf("%d",len[res[j]]);
for(int k=;k<=len[res[j]];k++) printf(" %d",b[res[j]][k]);
printf("\n");
}
} }

SGU 406 Goggle的更多相关文章

  1. 【406错误】 The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

    今天遇到一个奇怪的错误,关于Springmvc的,我明明在Controller方法中写了@ResponseBody,返回一个Map,结果报了406错误. 结果发现,少了一个jar包: 加上去就没事了.

  2. leetcode 406

    该算法题就是leetcode 406题, 题目描述: Suppose you have a random list of people standing in a queue. Each person ...

  3. Spring MVC Rest服务 返回json报406错误的解决办法

    @ResponseBody & @RequestBody @RequestBody 将 HTTP 请求正文插入方法中,使用适合的HttpMessageConverter将请求体写入某个对象. ...

  4. Spring MVC 4.1.4 RESTFUL风格返回JSON数据406错误处理

    Spring MVC 4.1.4 RESTFUL风格返回JSON数据406错误处理 今天在使用spring4.1.4,使用ResponseBody注解返回JSON格式的数据的时候遇到406错误. 解决 ...

  5. POSTMAN发起请求收到乱码 http 406错误

    web前段异常: The resource identified by this request is only capable of generating responses with charac ...

  6. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  7. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  8. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  9. Spring mvc 下Ajax获取JSON对象问题 406错误

    我在学习springmvc过程中(我的项目是配置的后缀是.html),从controller返回对象. 如果我不使用 mvc-annotation-driver,而是手动配置,AnnotationMe ...

随机推荐

  1. pre,html转义,abbr缩写,表格table

    <pre></pre>预定义文本标签pre(保留换行和空格) <sdds>对html转义 <abbr title="sddsdsds"&g ...

  2. MySQL权限操作:Grant、Revoke

    数据库操作: 创建数据库.创建表——CREATE 删除数据库.删除表——DROP 删除表内容——TRUNCATE.DELETE(后者效率低.一行一行地删除记录) 查询数据库.查询表——SELECT 插 ...

  3. 分别使用docx4j,jacob将文字与图片插入word中书签位置

    项目中需要将一段文字,与人员的签名(图片)插入到上传的word中,上网查询了一下,有许多种方式可以向word中插入文字,发现docx4j与jacob都为比较常见的解决方案,于是就先使用的docx4j进 ...

  4. hadoop 初探之第二篇(杂谈)

    NameNode:名称节点,主要功能在于实现保存文件元数据,这些元数据直接保存在内存中,为了保证元数据的持久性,而也会周期性的同步到磁盘上去.磁盘上的数据通常被称为元数据的映像数据 image fil ...

  5. JSON解析代码

    /** * 解析有数据头的纯数组 */ private void parseHaveHeaderJArray() { //拿到本地JSON 并转成String String strByJson = J ...

  6. Codeforces Round #213 (Div. 1) B - Free Market 思维+背包 好题

    B - Free Market 思路:这个题怎么说呢,迷惑性很大,题目里说了交换了两个集合的时候如果有相同元素不能交换,感觉如果没 这句话能很快写出来, 其实当交换的两个集合有重复元素的时候只要交换那 ...

  7. MySQL性能优化(七·下)-- 锁机制 之 行锁

    一.行锁概念及特点 1.概念:给单独的一行记录加锁,主要应用于innodb表存储引擎 2.特点:在innodb存储引擎中应用比较多,支持事务.开销大.加锁慢:会出现死锁:锁的粒度小,并发情况下,产生锁 ...

  8. 七牛云整合Ueditor的ThinkPHP版本

    首先去七牛云官网下载phpSDK工具放在Think/library/Vendor下. ueditor后台调用方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  9. 虚拟机zookeeper和hbase集群搭建

    集群zookeeper dataDir=/usr/local/zookeeper/dataDir dataLogDir=/usr/local/zookeeper/dataLogDir # the po ...

  10. CSUOJ 1895 Apache is late again

    Description Apache is a student of CSU. There is a math class every Sunday morning, but he is a very ...