1024 Developer Day test summary

Synchronization: https://buringstraw.win/archives/67/

1024 Developer Day test summary

Big feast, try to test what ah

Today's topic can be found in Los Valley, so we face a problem letting go. .

Math (math 1S 128M)

P3123 said Bessie Bessie Goes Moo moo

When submitting electronic classrooms stuck, take u disk copy up math.cppand become garbled. . .Although written only 30 minutes

First, the complexity of the direct enumeration This question is \ (500 ^ 7 \) , it can not be over.

And since the remainder additive, multiplicative nature of the case so long as the count is divided by 7 on the line, complexity \ (7 ^ 7 \) , run fast

(Luo Gu 提高+/省选-difficulty is serious about it)

Seven sets of code I am sorry for not impress. . .

#include <cstdio>

long long qz[27][8];
int n;
int main(void) {
//  freopen("math.in", "r", stdin);
//  freopen("math.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        char T[2];
        scanf("%s", T);
        int t;
        scanf("%d", &t);
        ++qz[T[0] - 'A'][(t + 700000) % 7];
    }
    long long res = 0;
    for (int i = 0; i <= 6; ++i) {
        for (int j = 0; j <= 6; ++j) {
            for (int k = 0; k <= 6; ++k) {
                for (int l = 0; l <= 6; ++l) {
                    for (int m = 0; m <= 6; ++m) {
                        for (int p = 0; p <= 6; ++p) {
                            for (int q = 0; q <= 6; ++q) {
                                if (((i + j * 2 + k * 2 + l) * (m + p + j + k) * (q + 2 * p)) % 7 == 0) {
                                    res += (qz['B' - 'A'][i] * qz['E' - 'A'][j] * qz['S' - 'A'][k] * qz['I' - 'A'][l] * qz['G' - 'A'][m] * qz['O' - 'A'][p] * qz['M' - 'A'][q]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    printf("%lld\n", res);
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}

Palindrome path (path 1S 128M)

Path P3126 palindrome Palindromic Paths

He called dfs, won 8 points

Correct answer is dp, at the same time began to walk from the left and right corners, two identical if the current grid, the state will be able to transfer.

iRepresents a few steps, jthe upper left corner of the departure went the first few lines, irepresents a departure from the lower right corner and walked the first few lines

The first through columns iwith jor kcalculated.

f[i][j][k]=f[i - 1][j - 1][k] + f[i - 1][j][k + 1] + f[i - 1][j][k] + f[i - 1][j - 1][ k - 1]

However, \ (500 ^ 3 \) is not only ultra-scale data at more than 512M memory limit (pro-test), so pressure level.

Because the new state and only i - 1, j, k, j - 1, k + 1are, therefore squeeze out i, jreverse enumeration, kenumeration reordering.

Note that j, kthe relationship between the starting point and the number of steps.

#include <cstdio>
#include <iostream>

const int MOD = 1000000007;

long long f[505][505];
char mp[505][505];
int n;

int main (void) {
    #ifndef ONLINE_JUDGE
    freopen("path.in", "r", stdin);
    freopen("path.out", "w", stdout);
    #endif
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            std::cin >> mp[i][j];
        }
    }
    if (mp[1][1] != mp[n][n]) {
        printf("0\n");
        return 0;
    }
    f[1][n] = 1;
    for (int i = 2; i <= n; ++i) {
        for (int j = i; j >= 1; --j) {
            for (int k = n - i + 1; k <= n; ++k) {
                if (mp[j][i - j + 1] == mp[k][2 * n - i - k + 1]) {
                    f[j][k] = f[j - 1][k + 1] + f[j - 1][k] + f[j][k + 1] + f[j][k];
                    f[j][k] %= MOD; 
                }
                else {
                    f[j][k] = 0;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += f[i][i];
        ans %= MOD;
    }
    printf("%d\n", ans);
    return 0;
}

Metropolis (city 1S 128M)

P3459 MEG Megalopolis

This question is used to search words with salad Google translation turned out to be true magic

Suona said it is dfssequence of template questions, learn a bit and found that really yes.

#include <cstdio>

const int MAXN = 5e5 + 5;

struct ed {
    int to, nex, w;
} e[MAXN];

int head[MAXN];
int newp, n, m, time;
int l[MAXN], r[MAXN];//以p为根的子树在dfs序中的左右端点 

namespace sz {
    int c[MAXN * 4];
    inline int lowbit (int x) {
        return x & (-x);
    }
    
    void add (int k, int x) {
        for (int i = k; i <= n; i += lowbit(i)) {
            c[i] += x;
        }
    }
    
    int query (int x) {
        int ans = 0;
        for (int i = x; i >= 1; i -= lowbit(i)) {
            ans += c[i];
        }
        return ans;
    }
}

void insert (int p1, int p2) {
    ++newp;
    e[newp].to = p2;
    e[newp].nex = head[p1];
    head[p1] = newp;
}

void dfs (int p, int fa) {
    l[p] = ++time;
    for (int i = head[p]; i; i = e[i].nex) {
        int y = e[i].to;
        if (y == fa) continue;
        dfs(y, p);
    }
    r[p] = time;
}

int main (void) {
    #ifndef ONLINE_JUDGE
    freopen("city.in", "r", stdin);
    freopen("city.out", "w", stdout);
    #endif
    scanf("%d", &n); 
    for (int i = 1; i < n; ++i) {
        int p1, p2;
        scanf("%d%d", &p1, &p2);
        insert(p1, p2);
        insert(p2, p1);
    }
    dfs(1, 0);
    for (int i = 2; i <= n; ++i) {
        sz::add(l[i], 1);
        sz::add(r[i] + 1, -1);
    }
    scanf("%d", &m);
    for (int i = 1; i <= n + m - 1; ++i) {
        char T[2];
        int x, y;
        scanf("%s %d", T, &x);
        if (T[0] == 'W') {
            printf("%d\n", sz::query(l[x]));
        }
        else {
            scanf("%d", &y);
            sz::add(l[y], -1);
            sz::add(r[y] + 1, 1);
        }
    }
    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}

Guess you like

Origin www.cnblogs.com/buringstraw/p/11735536.html