zoukankan      html  css  js  c++  java
  • SGU 406 Goggle

    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
    
     1 #include<iostream>  
     2 #include<string.h>  
     3 #include<stdio.h>  
     4 #include<ctype.h>  
     5 #include<algorithm>  
     6 #include<stack>  
     7 #include<queue>  
     8 #include<set>  
     9 #include<math.h>  
    10 #include<vector>  
    11 #include<map>  
    12 #include<deque>  
    13 #include<list>  
    14 #define maxn 200
    15 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
    ",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("
    ");
    43         }
    44     }
    45     
    46 }
    View Code
  • 相关阅读:
    hdu-3001 三进制状态压缩+dp
    最长公共子序列(LCS)
    矩阵最优路线DP
    CF-721C DAG图拓扑排序+费用DP
    拓扑排序
    BFS+二进制状态压缩 hdu-1429
    DAG最长路问题 hdu-1224
    并查集-解决区间和纠错问题 hdu-3038
    hdu 4972 根据每轮篮球赛分差求结果
    hdu 1116 欧拉回路+并查集
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3880023.html
Copyright © 2011-2022 走看看