Hdu-3724-Encoded Barcodes

Source: Internet
Author: User

Question: There are N products with names consisting of lower-case letters and M inquiries. Each inquiry comes with a K and then a K bar code. Each bar code represents one lower-case letter, these K bar codes are connected into consecutive K letters as the prefix. The number of product name prefixes is counted (repeated ), output the statistics of M queries (1 <= N <= 10000, 1 <= M <= 2000, 0 <K <= 30, Product Name Length <= 30 ).
 

--> After the Trip is organized, convert the bar code to lowercase letters (1 if the value is greater than the average value, or 0 if the value is greater than the average value, and calculate the ASCII code), connect the strings, locate and sum the values in the Trip.

 

#include <cstdio>#include <cstring>using namespace std;const int maxn = 30 + 5;const int maxb = 8 + 5;int N, M, K, bit[maxb];double bar[maxb];char qus[maxn];struct node{    int cnt;    node *next[26];    node(){        cnt = 0;        memset(next, 0, sizeof(next));    }};struct Trip{    node *root;    int ret;    Trip(){        root = new node;        ret = 0;    }    int idx(char c){        return c - 'a';    }    void insert(char *s){        int len = strlen(s), i;        node *t = root;        for(i = 0; i < len; i++){            int c = idx(s[i]);            if(!t->next[c]) t->next[c] = new node;            t->next[c]->cnt++;            t = t->next[c];        }    }    void solve(){        node *t = root;        int len = strlen(qus), i;        for(i = 0; i < len; i++){            int c = idx(qus[i]);            if(!t->next[c]) break;            t = t->next[c];        }        if(i == len) ret += t->cnt;    }    void print(){        printf("%d\n", ret);    }};int main(){    char product[maxn];    int i, j, k;    while(scanf("%d%d", &N, &M) == 2){        Trip trip;        for(i = 0; i < N; i++) {            scanf("%s", product);            trip.insert(product);        }        for(i = 0; i < M; i++){            int cnt = 0;            scanf("%d", &K);            for(j = 0; j < K; j++){                double sum = 0;                for(k = 0; k < 8; k++){                    scanf("%lf", &bar[k]);                    sum += bar[k];                }                sum /= 8;                int ASCII = 0;                for(k = 0; k < 8; k++) if(bar[k] > sum) ASCII += (1 << (7-k));                qus[cnt++] = (char)ASCII;            }            qus[cnt] = '\0';            trip.solve();        }        trip.print();    }    return 0;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.