Ultraviolet A 1519, ultraviolet

Source: Internet
Author: User

Ultraviolet A 1519, ultraviolet

Link: Ultraviolet A 1519-Dictionary Size

A dictionary composed of n strings. Now you need to add new words and select non-empty prefixes and non-empty suffixes from existing words to form a new word. Ask how many words can be made up.

Solution: Create a Prefix Tree and a suffix tree, and add a string with a length of 1 after deducting the middle part.

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 400005;const int sigma_size = 26;typedef long long ll;struct Tire {    int sz, g[maxn][sigma_size];    int c[sigma_size];    void init ();    int idx(char ch);    void insert(char* s);}pre, suf;int main () {    int N;    while (scanf("%d", &N) == 1 && N) {        char word[45];        int vis[sigma_size];        memset(vis, 0, sizeof(vis));        pre.init();        suf.init();        for (int i = 0; i < N; i++) {            scanf("%s", word);            int n = strlen(word);            if (n == 1)                vis[word[0] - 'a'] = 1;            pre.insert(word);            reverse(word, word + n);            suf.insert(word);        }        ll ans = (ll)(pre.sz - 1) * (suf.sz - 1);        for (int i = 0; i < sigma_size; i++)            ans -= (ll)pre.c[i] * suf.c[i] - vis[i];        printf("%lld\n", ans);    }    return 0;}void Tire::init () {    sz = 1;    memset(g[0], 0, sizeof(g[0]));    memset(c, 0, sizeof(c));}int Tire::idx (char ch) {    return ch - 'a';}void Tire::insert(char* s) {    int u = 0, n = strlen(s);    for (int i = 0; i < n; i++) {        int v = idx(s[i]);        if (g[u][v] == 0) {            memset(g[sz], 0, sizeof(g[sz]));            g[u][v] = sz++;            if (i)                c[v]++;        }        u = g[u][v];    }}

How can I protect my skin and protect my skin when swimming in summer? (From to every morning, 20 days, how can I stay the same?) What kind of sunscreen?

1. You can buy the type of sun protection swimsuit (like water with only hands and feet and head exposed), the head is a sun protection swimming cap (full head, only glasses and nose exposure.
2. swimming ashore, you can choose to rest in the shade, or use a bath towel to shoulder to protect your skin.
3. After the game, you should immediately wipe your body with moisture, because the wet skin is sensitive to sunlight.
4. place some oil or sunscreen on the exposed skin.
This is basically the case. Please handle it as appropriate!


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.