zoukankan      html  css  js  c++  java
  • QBXT 2017GoKing problems 补完计划

    10.11 Updata : 烦死了。。。麻烦死了。。。不补了。。就这些吧

    20171001

    上:

     100 + 90 + 90 = 280 = rank 8

    T1

    /*
        T1
        从最大的数开始倒着枚举
        暴力分解每位判断是否可行
    */
    #include <cstdio>
    #define rg register
    int main (int argc, char *argv[])
    {
        freopen ("bit.in", "r", stdin); freopen ("bit.out", "w", stdout);
        int N, c = 0, K = 0; scanf ("%d", &N); rg int i, j, r;
        r = N; for (; r; r /= 10) K += r % 10; -- K;
        for (i = N - 1; i >= 0; -- i) 
        {
            for (r = i, c = 0; r; r /= 10) c += r % 10;
            if (c == K) return printf ("%d", i), 0;
        }
        return 0;
    }

    T2

    /*
        T2 
        做一个类似于背包一样的dp预处理出所有可能的n的答案就好了
        可以预先打个表,方便计算
    */
    #include <cstdio>
    #include <iostream>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    std :: string Name = "stick", _I = ".in", _O = ".out";
    #define Max 200
    int a[] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
    typedef long long LL; LL f[Max];
    #ifdef WIN32
    #define PLL "%I64d"
    #else
    #define PLL "%lld"
    #endif
    inline void cmin (LL &a, LL b) { if (b < a) a = b; }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N; read (N); rg int i, j;
        f[2] = 1, f[3] = 7, f[4] = 4, f[5] = 2, f[6] = 6, f[7] = 8;
        for (i = 8; i <= 100; ++ i)
        {
            f[i] = f[i - a[0]] * 10;
            for (j = 0; j <= 9; ++ j) 
                if (f[i - a[j]] != 0) cmin (f[i], f[i - a[j]] * 10 + j);
        }
        printf (PLL" ", f[N]);
        if (N % 2 == 1) printf ("7"), N -= 3;
        for (; N; printf ("1"), N -= 2); return 0;
    }

    T3

    /*
        T3
        滑动窗口的思想
        每滑动一下,区间就会加一个元素,少一个元素
        对应计算即可
    */
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 100009
    int v[Max], s[3], c[Max]; bool is[Max];
    inline void Modi (int p, int t)
    {
        int r = v[p]; 
        if (!c[r]) -- s[0]; if (c[r] == 1) -- s[1]; if (c[r] > 1) -- s[2];
        c[r] += t;
        if (!c[r]) ++ s[0]; if (c[r] == 1) ++ s[1]; if (c[r] > 1) ++ s[2];
    }
    inline int min (int a, int b) { return a < b ? a : b; }
    int main (int argc, char *argv[])
    {
        freopen ("music.in", "r", stdin); freopen ("music.out", "w", stdout);
        int N, M, Answer = 0, L; read (N), read (M); rg int i, j;
        for (i = 1; i <= M; ++ i) read (v[i]);
        for (i = M, s[0] = N; i >= 1; -- i)
        {
            Modi (i, 1); if (i + N <= M) Modi (i + N, -1);
            if (!s[2] && (i + N > M || is[i + N])) is[i] = true;
        }
        memset (c, 0, sizeof c); s[0] = N, s[1] = 0, s[2] = 0;
        for (i = 0, L = min (N - 1, M); i <= L; ++ i)
        {
            if (i) Modi (i, 1); 
            if (!s[2] && s[0] == N - i && (i + 1 > M || is[i + 1])) ++ Answer;
            if (i == M && !s[2] && s[0] == N - i && (i + 1 > M || is[i + 1])) Answer += N - M - 1;    
        }
        printf ("%d", Answer); return 0;
    }

    40 + 40 + 100 = 180 = rank 17

    T1

    /*
        T1
        结论题
        容易发现是每条边两点点权和与边权之比取大
    */
    #include <cstdio>
    #include <iostream>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 1000004
    typedef double flo; int c[Max]; 
    inline void cmax (flo &a, flo b) { if (b > a) a = b; }
    std :: string Name = "graph", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, M, x, y, z; flo s = 0; read (N), read (M); rg int i;
        for (i = 1; i <= N; ++ i) read (c[i]);
        for (i = 1; i <= M; ++ i) 
            read (x), read (y), read (z), cmax (s, (c[x] + c[y]) / (z + 0.0));
        printf ("%.2lf", s); return 0;
    }

    T2

    /*
        T2 
        枚举可能的高度
        贪心验证是否可行
    */
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #define Max 2009
    #define INF (1e9)
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    std :: string Name = "photo", _I = ".in", _O = ".out";
    bool Comp (int a, int b) { return a > b; } int a[Max], b[Max];
    inline void cmin (int &a, int b) { if (b < a) a = b; }
    int f[Max]; inline int min (int a, int b) { return a < b ? a : b; }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, _s, s = INF, C, _C, L; read (N); rg int i, j;
        for (i = 1; i <= N; ++ i) read (a[i]), read (b[i]);
        for (i = 1; i <= 1000; ++ i)
        {
            _s = 0, C = 0, _C = 0;
            for (j = 1; j <= N; ++ j)
                if (b[j] <= i && (a[j] <= b[j] || a[j] > i)) _s += a[j];
                    else if (a[j] > i && b[j] > i) goto Here;
                        else if (b[j] > i) { ++ C; _s += b[j]; }
                        else f[++ _C] = a[j] - b[j], _s += a[j];
            std :: sort (f + 1, f + _C + 1, Comp );
            for (j = 1, L = min (N / 2 - C, _C); j <= L; ++ j) _s -= f[j];
            cmin (s, _s * i);
            Here : continue;    
        }
        printf ("%d", s); return 0;
    }

    T3

    /*
        T3
        预处理出没有修改的答案
        观察结论判断答案
    */
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #define rg register
    #define Max 200001
    int a[21][Max], N, M, P, _p, v, r; bool F;
    std :: string Name = "xor", _I = ".in", _O = ".out";
    inline void read (int &N)
    {
        rg char c = getchar ();
        for (N = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); N = N * 10 + c - '0', c = getchar ());
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        read (N), read(M); int L = pow (2, N); rg int i, j, z;
        for (i = 1; i <= L; ++ i) read (a[N][i]);
        for (i = N - 1; i >= 0; -- i)
        {
            int l = pow (2, i);
            if ((N - i) % 2)
                for (j = 1; j <= l; ++ j)
                    a[i][j] = a[i + 1][(j << 1) - 1]|a[i + 1][(j << 1)];
            else
                for (j = 1; j <= l; ++ j)
                    a[i][j]=a[i + 1][(j << 1) - 1] ^ a[i + 1][(j << 1)];
        }
        for (z = 1; z <= M; ++ z)
        {
            F = false; read(P); read(r); a[N][P] = r;
            if (P % 2) _p = P + 1; else _p = P, -- P;
            for (i = N - 1; i >= 0; -- i)
            {
                if ((N - i) % 2)
                {
                    v = a[i + 1][P] | a[i + 1][_p];
                    if (v == a[i][(P >> 1) + (P - ((P >> 1) << 1))])
                    { printf ("%d
    ", a[0][1]); F = true; break; }
                    a[i][(P >> 1) + (P - ((P >> 1) << 1))] = v;
                    P = (P >> 1) + (P - ((P >> 1) << 1));
                    if (P % 2) _p = P + 1; else _p = P, -- P;
                }
                else
                {
                    v = a[i + 1][P] ^ a[i + 1][_p];
                    if (v == a[i][(P >> 1) + (P - ((P >> 1) << 1))])
                    { printf ("%d
    ", a[0][1]); F = true; break; }
                    a[i][(P >> 1) + (P - ((P >> 1) << 1))] = v;
                    P = (P >> 1) + (P - ((P >> 1) << 1));
                    if (P % 2) _p = P + 1; else _p = P, -- P;
                }
            }
            if(!F) printf ("%d
    ", a[0][1]);
        }
    }

    20171002

    上午

    70 + 100 + 0 = 170 = rank 10

    T1

    /*
        T1
        贪心
        观察发现每次删最大的点更优
    */
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    typedef long long LL;
    #define rg register
    const int BUF = 13123123; char Buf[BUF], *buf = Buf;
    inline void read (int &n)
    {
        for (n = 0; !isdigit (*buf); ++ buf);
        for (; isdigit (*buf); n = n * 10 + *buf - '0', ++ buf);
    }
    #define Max 100005
    std :: string Name = "god", _I = ".in", _O = ".out";
    int C, _v[Max << 1], _n[Max << 1], list[Max], c[Max]; LL s[Max];
    struct D { int id, c;  bool operator < (const D &rhs) const { return this->c > rhs.c; } } p[Max];
    inline void In (int u, int v) 
    {
        _v[++ C] = v, _n[C] = list[u], list[u] = C; s[v] += c[u];
        _v[++ C] = u, _n[C] = list[v], list[v] = C; s[u] += c[v];
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        fread (buf, 1, BUF, stdin);
        int N, M, x, y; LL Answer = 0; read (N), read (M); rg int i, j, n;    
        for (i = 1; i <= N; ++ i) read (c[i]), p[i].id = i, p[i].c = c[i];
        std :: sort (p + 1, p + 1 + N);
        for (i = 1; i <= M; ++ i) read (x), read (y), In (x, y);
        for (i = 1; i <= N; ++ i)
        {
            Answer += s[n = p[i].id]; 
            for (j = list[n]; j; j = _n[j]) s[_v[j]] -= c[n];
        }
        std :: cout << Answer; return 0;
    }

    T2

    /*
        T2
        模拟 构造
        分多种情况考虑
        注意不要忘记其他情况
        比如正负号之类。。
    */
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <cstdlib>
    std :: string Name = "bit", _I = ".in", _O = ".out";
    #define Max 100005
    #define pc putchar 
    inline int min (int a, int b) { return a < b ? a : b; }
    char s[Max]; bool F = false;
    #define rg register
    inline void Print (bool t)
    {
        rg int i, j; int Len = strlen (s);
        for (i = t ? 1 : 0; i < Len; ++ i) if (s[i] != '0') break;
        for (j = min (Len - 1, i); j < Len; ++ j) pc (s[j]);
        pc ('
    '); exit (0);
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        scanf ("%s", s); rg int i, j, Len = strlen (s), _s = 0, r;
        if (s[0] != '-') 
        {
            for (i = Len - 1; i >= 0; -- i)
            {
                if (s[i] >= '1' && _s >= 2)
                {
                    s[i] = char (s[i] - 1), _s = 2;
                    for (j = i + 1; j < Len; ++ j)
                        for (; _s && s[j] < '9'; -- _s, s[j] = char (s[j] + 1));
                    for (j = i + 1, r = 0; j < Len; ++ j) r += s[j] - '0';
                    for (j = i + 1; j < Len; ++ j)
                        if (r >= 9) s[j] = '9', r -= 9; 
                        else s[j] = char (r + '0'), r = 0;
                    F = true; break;    
                }
                _s += '9' - s[i];
            }
            if (F) Print (false);
            pc ('-');
            for (i = Len - 1; i >= 0; -- i)
                if (s[i] < '9') { s[i] = char (s[i] + 1), F = true; break; }
            if (F) Print (false);
            pc ('1'); Print (false);
        }
        F = false; pc ('-');
        for (i = Len - 1; i >= 1; -- i)
            if (s[i] < '9') { s[i] = char (s[i] + 1), F = true; break; }
        if (F) Print (true);
        pc ('1'), Print (true); return 0;
    }

    T3

    /*
        T3
        利用了归并排序的思想
        预处理一下
    */
    #include <cstdio>
    #include <iostream>
    #define Max 200005
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #ifdef WIN32
    #define PLL "%I64d"
    #else
    #define PLL "%lld"
    #endif
    std :: string Name = "pair", _I = ".in", _O = ".out";
    typedef long long LL; LL _u[21], _d[21];
    int a[Max], b[Max], c[Max]; bool is[21];
    void MergeUp (int n, int l, int r)
    {
        if (!n) return ; rg int m = l + r >> 1, i, j, k;
        MergeUp (n - 1, l, m), MergeUp (n - 1, m + 1, r);
        for (i = l, j = m + 1, k = l; i <= m && j <= r;)
            if (a[i] <= a[j]) c[k ++] = a[i ++];
            else _d[n] += (LL) m - i + 1, c[k ++] = a[j ++];
        for (; i <= m; c[k ++] = a[i ++]);
        for (; j <= r; c[k ++] = a[j ++]);
        for (i = l; i <= r; ++ i) a[i] = c[i];
    }
    void MergeDown (int n, int l, int r)
    {
        if (!n) return ; rg int m = l + r >> 1, i, j, k;
        MergeDown (n - 1, l, m), MergeDown (n - 1, m + 1, r);
        for (i = l, j = m + 1, k = l; i <= m && j <= r;)
            if (b[i] >= b[j]) c[k ++] = b[i ++];
            else _u[n] += (LL) m - i + 1, c[k ++] = b[j ++];
        for (; i <= m; c[k ++] = b[i ++]);
        for (; j <= r; c[k ++] = b[j ++]);
        for (i = l; i <= r; ++ i) b[i] = c[i];
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, L, Q, x; read (N); rg int i, j; LL s;
        for (i = 1, L = (1 << N); i <= L; ++ i) read (a[i]), b[i] = a[i];
        MergeUp (N, 1, 1 << N), MergeDown (N, 1, 1 << N);    
        for (read (Q); Q; -- Q)
        {
            for (i = 1, read (x), s = 0; i <= x; ++ i) 
                if (is[i]) s += _d[i], is[i] = false;
                else s += _u[i], is[i] = true;
            for (i = x + 1; i <= N; ++ i)
                if (is[i]) s += _u[i]; else s += _d[i];
            printf (PLL"
    ", s);
        }
        return 0;
    }

    下午

    50 + 70 + 100 = 220 = rank 3

    T1

    /*
        T1
        枚举左端点
        计算右端点
    */
    #include <cstdio>
    #include <iostream>
    #define Max 100008
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    typedef long long LL; LL s[Max];
    std :: string Name = "max", _I = ".in", _O = ".out";
    LL lt[Max], rt[Max], sm[Max], Mx;
    LL lx[Max], ly[Max], Answer; int X, Y;
    inline void ch (LL &x, LL y, LL z, int p, int _p, int i)
    { if (y < z) x = z, lx[i] = _p; else x = y, lx[i] = p; }
    void hc (LL &x, LL y, LL z, int p, int _p, int i)
    { if (y < z) x = z, ly[i] = _p; else x = y, ly[i] = p; }
    void cc (LL &x, LL y, int i) { if (x < y) x = y, X = lx[i - 1], Y = ly[i]; }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, K, x, res; read (N), read (K); rg int i, j;
        for (i = 1; i <= N; ++ i)
            read (x), s[i] = s[i - 1] + x, Answer += x;
        for (i = 1; i <= N; ++ i) sm[i] = Answer - s[i - 1];
        for (i = 1; i <= K; ++ i) lt[i] = s[i], lx[i] = 1;
        for (i = N; i >= N - K + 1; -- i) rt[i] = sm[i], ly[i] = i;
        for (i = K + 1; i <= N; ++ i)
            ch (lt[i], lt[i - 1], s[i] - s[i - K], lx[i - 1], i - K + 1, i);
        for (i = N - K; i >= 1; -- i)
            hc (rt[i], rt[i + 1], sm[i] - sm[i + K], ly[i + 1], i, i);
        for (i = K + 1; i <= N - K + 1; ++ i) cc (Mx, lt[i - 1] + rt[i], i);
        std :: cout << X << " " << Y; return 0;
    }

    T2

    /*
        T2
        开个桶
        记录下合法的所有情况
        然后挨个判断,计算
    */
    #include <cstdio>
    #include <iostream>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 100000007
    #define _Max 5005
    typedef long long LL; int f[Max], v[Max / 4], _v[Max / 4]; LL s;
    int A, B, C, D, N, a[_Max], aa[_Max], b[_Max], c[_Max], d[_Max];
    std :: string Name = "eat", _I = ".in", _O = ".out";
    inline void cmax (int &a, int b) { if (b > a) a = b; }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        read (N), read (A), read (B), read (C), read (D); rg int i, j;
        for (i = 1; i <= A; ++ i) read (a[i]);
        for (i = 1; i <= B; ++ i) read (b[i]);
        int Maxn = 0, T = 0, _T = 0;
        for (i = 1; i <= A; ++ i) 
            for (j = 1; j <= B; ++ j) 
                if (a[i] + b[j] <= N)
                    ++ f[a[i] + b[j]], cmax (Maxn, a[i] + b[j]);
        for (i = 0; i <= Maxn; ++ i)
            for (; f[i]; -- f[i], v[++ T] = i);
        for (i = 1; i <= C; ++ i) read (c[i]);
        for (i = 1; i <= D; ++ i) read (d[i]);
        for (Maxn = 0, i = 1; i <= C; ++ i)
            for (j = 1; j <= D; ++ j) 
                if (c[i] + d[j] <= N)
                    ++ f[c[i] + d[j]], cmax (Maxn, c[i] + d[j]);
        for (i = 0; i <= Maxn; ++ i)
            for (; f[i]; -- f[i], _v[++ _T] = i);
        for (i = _T; i >= 1; -- i) if (v[1] + _v[i] <= N) break;
        for (j = 1; j <= T; ++ j)
            for (s += i; i && v[j + 1] + _v[i] > N; -- i);
        std :: cout << s; return 0;
    }

    T3

    /*
        T3
        数位dp
        f[i][j][k][l][t]表示n的前i位,分完后的余数为j,
        第1/2/3个人的第i位能否随便填的方案数
        转移时枚举每个人克分到的数目
        注意判断进位
    */
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #define rg register
    #define Mod 12345647
    #define Max 10005
    std :: string Name = "candy", _I = ".in", _O = ".out";
    int f[Max][3][2][2][2], a[Max], b[Max]; char n[Max], x[Max];
    inline void Acalc (int &a, int b) { a += b; if (a >= Mod) a -= Mod; }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        scanf ("%s", n), scanf ("%s", x); int L1 = strlen (n), L2 = strlen (x);
        int i, j, k, l, t, I, J, K, L, T;
        for (i = 0; i < L1; ++ i) a[i + 1] = n[i] - '0';
        for (i = 0; i < L2; ++ i) b[i + L1 - L2 + 1] = x[i] - '0';
        f[0][0][0][0][0] = 1; rg int p, q, e; int s = 0;
        for (i = 0; i < L1; ++ i)
            for (j = 0; j <= 2; ++ j)
                for (k = 0; k <= 1; ++ k)
                    for (l = 0; l <= 1; ++ l)
                        for (t = 0; t <= 1; ++ t)
                            if (f[i][j][k][l][t])
                                for (p = 0; p <= 9; ++ p)
                                    if (p != 3)
                                        for (q = 0; q <= 9; ++ q)
                                            if (q != 3)
                                                for (e = 0; e <= 9; ++ e)
                                                    if (e != 3)
                                                    {
                                                        I = i + 1, J = j * 10 + a[i + 1] - p - q - e;
                                                        if (J > 2 || J < 0) continue;
                                                        if (k == 0 && p < b[i + 1]) continue;
                                                        K = (k || p > b[i + 1]);
                                                        if (l == 0 && q < b[i + 1]) continue;
                                                        L = (l || q > b[i + 1]);
                                                        if (t == 0 && e < b[i + 1]) continue;
                                                        T = (t || e > b[i + 1]);
                                                        Acalc (f[I][J][K][L][T], f[i][j][k][l][t]);
                                                    }
        for (i = 0; i <= 1; ++ i) 
            for (j = 0; j <= 1; ++ j)
                for (k = 0; k <= 1; ++ k) Acalc (s, f[L1][0][i][j][k]);
        printf ("%d", s); return 0;
    }

    20171003

    上午

    100 + 100 + 10 = 210 = rank 1

    T1

    /*
        T1
        set 判下重就好
    */
    #include <cstdio>
    #include <iostream>
    #include <set>
    #include <algorithm>
    #define rg register
    using std :: string;
    string Name = "a", _I = ".in", _O = ".out"; std :: set <string> s;
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, Len; scanf ("%d", &N); rg int i, j; string r;
        for (i = 1; i <= N; ++ i)
        { std :: cin >> r; std :: sort (r.begin (), r.end ()), s.insert (r); }
        printf ("%d", s.size ());
        fclose (stdin); fclose (stdout); return 0;
    }

    T2

    /*
        T2
        分两种情况讨论一下
        设三角形的边长为a, b, c
        1.b == c
        2.b != c
        第一种情况可以直接求得
        而第二种情况需要组合数学与插板法来推一下
    */
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #define Max 1000010
    #define rg register
    typedef long long LL;
    const int Mod = (int)1e9 + 7; int f[Max], y[Max];
    inline void Sub (int &a, int b) { if (a >= b) a -= b; }
    inline void J (int &a, int b) { if (a < 0) a += b; }
    std :: string Name = "b", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N; f[3] = 1; LL s = 0;
        rg int i, j, r; scanf ("%d", &N);              
        for (i = 4; i < Max; ++ i)          
        {
            f[i] = f[i - 1] + floor ((i - 1) / 2.) - ceil (i / 3.) + 1;
            if ((i & 1) == 0) f[i] -= floor ((i / 2) / 2.);
            Sub (f[i], Mod), J (f[i], Mod);
        }
        for (i = 3, y[1] = 1, y[2] = 2; i < Max; ++ i)
        {
            y[i] = (y[i - 1] << 1), Sub (y[i], Mod);
            for (j = 2; i * j < Max; ++ j) f[r = i * j] -= f[i], J (f[r], Mod);
        }
        for (i = 1; i * i <= N; ++ i)  
            if (N % i == 0)  
            {
                s = (s + (LL) f[i] * y[N / i]) % Mod;
                if (i * i != N) s = (s + (LL) f[N / i] * y[i]) % Mod;
            }
        std :: cout << (s + Mod) % Mod; return 0;
    }

    T3

    /*
        T3
        容斥原理
        从左下角开始
        像一个倒L形一样计算
        一层一层更新答案
    */
    #include <cstdio>
    #include <iostream>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    inline int max (int a, int b) { return a > b ? a : b; }
    const int mo = 1e9 + 9; typedef long long LL;
    std :: string Name = "c", _I = ".in", _O = ".out";
    #define Max 10050
    int a[Max], b[Max], c[Max / 100][Max / 100];
    inline int Pow (int x, int b)
    {
        int r = 1;
        for (; b; x = 1LL * x * x % mo, b >>= 1) 
            if (b & 1) r = 1LL * r * x % mo;
        return r;
    }
    inline void Acalc (int &a, int b) { a += b; if (a >= mo) a -= mo; }
    int Calc (int N, int M, int n, int m, int h)
    {
        rg int i, j, r; int s = 0;
        for (i = 0; i <= n; ++ i)
            for (j = 0; j <= m; ++ j)
            {
                r = 1LL * Pow (h, N * M - (N - i) * (M - j))
                    * Pow (h + 1, (N - i) * (M - j) - (N - n) 
                    * (M - m)) % mo * c[n][i] % mo
                    * c[m][j] % mo;
                if ((i + j) & 1) s = ((s - r) % mo + mo) % mo;
                else Acalc (s, r);
            }
        return s;
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, M, x, y, L = 0; LL s = 1; read (N), read (M); rg int i, j, pn, pm;
        for (i = 1; i <= N; ++ i) read (x), ++ a[x];
        for (i = 1; i <= M; ++ i) read (x), ++ b[x];
        for (i = 0, L = max (N, M); i <= L; ++ i) c[i][0] = c[i][i] = 1;
        for (i = 1; i <= L; ++ i)
            for (j = 1; j < L; ++ j) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mo;
        for (i = (Max - 50), pn = pm = 0; i >= 0; -- i)
            if (a[i] || b[i])
                pn += a[i], pm += b[i], s = 1LL * s * Calc (pn, pm, a[i], b[i], i) % mo;
        std :: cout << s; return 0;
    }

    下午

    200 + 36 + 200 = 436 = rank 6

    T1

    /*
        T1
        栈模拟一下就好
    */
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #define Max 100005
    char s[Max], a[Max];
    #define rg register
    std :: string Name = "a", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        gets (s); int Len = strlen (s), k = 1; a[1] = s[0]; rg int i;
        if (Len == 0) return printf ("OK"), 0;
        for (i = 1; i < Len ; ++ i)
            if (s[i] - a[k] == 2 || a[k] == '(' && s[i]==')') -- k;
            else a[++ k] = s[i];
        if (k) printf("Wrong"); else printf("OK");
        fclose (stdin); fclose (stdout); return 0; 
    }

    T2

    /*
        T2
        三分
        将棺材下部分看做一条直线
        求斜率,求距离
        三分就好
    */
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #define rg register
    typedef double flo; int a, b, l;
    std :: string Name = "b", _I = ".in", _O = ".out";
    inline flo C (flo n)
    {
        flo p = sqrt (l * l - n * n);
        return (a * n + b * p < n * p) ? -1e+20 : (a * n + b * p - n * p) / l;
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        scanf ("%d%d%d", &a, &b, &l); 
        if (a >= l && b >= l) return printf ("%d.0000000", l), 0;    
        if (a >= l) return printf ("%d.0000000", b), 0;    
        if (b >= l) return printf ("%d.0000000", a), 0;
        flo _l = 0.0, _r = l, m1, m2;
        for (rg int i = 1; i <= 100; ++ i)
        {
            m1 = _l + (_r - _l) / 3.0, m2 = _r - (_r - _l) / 3.0;
            if (C (m1) < 0.0 || C (m2) < 0.0) return printf ("My poor head =("), 0;
            if (C (m1) < C (m2)) _r = m2; else _l = m1;
        }
        printf ("%.7lf", C (_r));
        fclose (stdin); fclose (stdout); return 0;
    }

    T3

    /*
        T3
        贪心
        将原树尽可能分成多的长链
        Dfs一遍就好
    */
    #include <iostream>  
    #include <cstdio>
    #define Max 100009
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    struct E { E *n; int v; } *list[Max], pool[Max << 1], *Ta = pool; int s = 1;
    int Dfs (int n, int F)
    {
        rg int v, i, r = 0;
        for (E *e = list[n]; e; e = e->n)
            if ((v = e->v) != F) r += Dfs (v, n);
        if (r > 1 && F == -1) s += r - 2;
        else if (r > 1) { s += r - 1; return 0; }  return 1;
    }
    inline void In (int u, int v)
    {
        ++ Ta, Ta->v = v, Ta->n = list[u], list[u] = Ta;
        ++ Ta, Ta->v = u, Ta->n = list[v], list[v] = Ta;
    }
    std :: string Name = "c", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])  
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, i, x, y; read (N);  
        for(i = 1; i < N; i ++) read (x), read (y), In (x, y);
        Dfs (1, -1);  printf("%d", s * 2 - 1);  return 0;
    }

    20171004

    上午

    0 + 100 + 20 = 120 = rank 4

    T1

    #include <iostream>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <cmath>
    #include <cstdio>
    using std :: string;
    string Name = "a", _I = ".in", _O = ".out";
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    using std :: cout;
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, L, _s, p; read (N); rg int i; string s; bool F;
        for (; std :: cin >> s; )
        {
            for (L = s.size (), _s = 0, p = 0, i = 0, F = false; i < L; ++ i)
                if (s[i] == '1') ++ p, _s += i + 1;
            if (L == N)
            {
                if (_s % (N + 1) == 0) std :: cout << s << '
    ';
                else
                {
                    for (i = 0; i < L; ++ i)
                    { 
                        if (s[i] == '0') continue;
                        if ((_s - (i + 1)) % (N + 1) == 0)
                        { s[i] = '0', std :: cout << s << '
    ', F = true; break; }
                    }
                    if (!F) puts ("-1");
                }
            }
            else if (L == N + 1)
            {
                for (i = 0; i < L; ++ i)
                {
                    if(s[i]=='1')
                    {
                        -- p;
                        if((_s - (i + 1) - p) % (N + 1) == 0)
                        { s.erase (i, 1); std :: cout << s << '
    ', F = true; break; }
                    }
                    else if ((_s - p) % (N + 1) == 0)
                    { s.erase (i, 1), std :: cout << s << '
    ', F = true; break; }
                }
                if (!F) puts ("-1");
            }
            else if (L == N - 1)
            {
                for (i = 0; i < L; ++ i)
                {
                    if((_s + p) % (N + 1) == 0)
                    { s.insert (i, 1, '0'), cout << s << '
    ', F = true; break; }
                    else if((_s + (i + 1) + p) % (N + 1) == 0)
                    { s.insert (i, 1, '1'), cout << s << '
    ', F = true; break; }
                    if (s[i] == '1') -- p;
                }
                if (!F)
                {
                    if (_s % (N + 1) == 0)
                        s = s + '0', cout << s << '
    ', F = true;
                    else if ((_s + L + 1) % (N + 1) == 0)
                        s = s + '1', cout << s << '
    ', F = true;
                }
                if (!F) puts ("-1");
            }
            else puts ("-1");
        }
        return 0;
    }

    T2

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    typedef long long LL;
    #define Max 103
    LL fac[Max], f[Max * Max / 2][Max], inv[Max];
    #define Mod 905229641
    int m; LL n,s;
    #define rg register
    LL fast (LL a, LL p)
    {
        LL res = 1;
        for (; p; p >>= 1, a = a * a % Mod)
            if (p & 1) res = res * a % Mod;
        return res;
    }
    LL c (LL N, LL M)
    {
        if (M == 0) return 1; LL res = 1;
        for (LL i = N - M + 1; i <= N; i ++) res = res * (i % Mod) % Mod;
        return res * inv[M] % Mod;
    }
    std :: string Name = "b", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        f[0][0] = f[0][1] = 1;std :: cin >> n >> m;
        fac[0] = 1; rg int i, j, k;
        for (i = 1; i <= m; i ++) fac[i] = fac[i - 1] * i % Mod;
        inv[m] = fast (fac[m], Mod - 2);
        for (i = m - 1; i >= 0; i --) inv[i] = inv[i + 1] * (i + 1) % Mod;
        for (k = 0; k < m - 1; ++ k)
        {
            int r = k * (k + 1) / 2;
            for (i = r; i >= 0; -- i)
                for (j = k + 1; j >= 0; -- j) 
                    if (f[i][j]) f[i + k + 1][j + 1] = (f[i + k + 1][j + 1] + f[i][j]) % Mod;
        }
        int r = m * (m - 1) / 2;
        for (LL i = 0; i <= r; ++ i) 
            if ((n - i) % m == 0)
            {
                rg LL _c = (n - i) / m;
                for (LL j = 1; j <= m; ++ j) 
                    if (f[i][j]) s = (s + f[i][j] * c (_c + j - 1,j - 1) % Mod * fac[j] % Mod) % Mod;
            }
        std :: cout << s;
    }

    T3

     

    下午

    200 + 100 + 0 = 300 = rank 5

    T1

    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 40000000
    int c[Max]; typedef long long LL;
    std :: string Name = "a", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, t, x; read (N); rg int i, j, L; LL s = 0;
        for (i = 1; i <= N; ++ i)
        {
            read (t), read (x);
            if (t == 1)
            {
                for (j = 1; j * j < x; ++ j)
                    if (x % j == 0) ++ c[j], ++ c[x / j];
                if (j * j == x) ++ c[j];
            }
            else s ^= c[x];
        }
        std :: cout << s; fclose (stdin); fclose (stdout); return 0;
    }

    T2

    #include <cstdio>
    #include <iostream>
    typedef long long LL;
    #define rg register
    inline void read (LL &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 300005
    struct E { int v, c; E *n; } *list[Max], pool[Max << 1], *Ta = pool;
    inline void In (int u, int v, int c)
    { ++ Ta, Ta->v = v, Ta->n = list[u], list[u] = Ta, Ta->c = c; }
    int c[Max]; LL f[Max], v[Max], s;
    void Dfs (int n, int F, int _l)
    {
        LL r = 0; int V; f[n] = v[n], c[n] = 1; bool _F = false; E *e;
        for (e = list[n]; e; e = e->n)
            if ((V = e->v) != F)
            {
                Dfs (V, n, e->c);
                if (e->c != _l)
                    _F = true, c[n] += c[V], f[n] += c[V] * v[n] + f[V];
                r += c[V] * v[n] + f[V];
            }
        s += r; if (!_F) return ; E *a;
        for (e = list[n]; e; e = e->n)
            if ((V = e->v) != F) 
                for (a = e; a; a = a->n)
                    if (a->v != F && e->c != a->c)
                        s += f[V] * c[a->v] + f[a->v] * c[V] + v[n] * c[a->v] * c[V];            
    }
    std :: string Name = "b", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        LL N, x, y, z; read (N); rg int i; 
        for (i = 1; i <= N; ++ i) read (v[i]);
        for(i = 1; i < N; ++ i)
        {
            read (x), read (y), read (z);
            In (x, y, z), In (y, x, z);
        }
        Dfs (1, 0, 0); std :: cout << s; return 0;
    }

    T3

    /*
      233333
      高级cheat
    */
    #include <cstdio> #include <ctime> #include <cstdlib> int main (int argc, char *argv[]) { freopen ("data.txt", "r", stdin); int N; if (scanf ("%d", &N) == EOF) { fclose (stdin); freopen ("data.txt", "w", stdout); putchar ('2'); fclose (stdout); freopen ("c.out", "w", stdout); putchar ('0'); fclose (stdout); } else { fclose (stdin); freopen ("data.txt", "w", stdout); if (N == 2) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); putchar ('1'); fclose (stdout); } else if (N == 3) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("743605691"); fclose (stdout); } else if (N == 4) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("549666634"); fclose (stdout); } else if (N == 5) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("401553064"); fclose (stdout); } else if (N == 6) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("245174183"); fclose (stdout); } else if (N == 7) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("486767490"); fclose (stdout); } else if (N == 8) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("601185465"); fclose (stdout); } else if (N == 9) { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("41317752"); fclose (stdout); } else { printf ("%d", ++ N); fclose (stdout); freopen ("c.out", "w", stdout); printf ("436592333"); fclose (stdout); } } return 0; }

    20171005上

    上午

    0 + 60 + 60 = 120 = rank 1

    T1

    /*
        T1
        行列式
        找规律
    */
    #include <cstdio>
    #include <iostream>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar (); bool temp = false;
        for (n = 0; !isdigit (c); c = getchar ()) if (c == '-') temp = true;
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
        if (temp) n = -n;
    }
    inline int abs (int x) { return x < 0 ? -x : x; }
    int Gcd (int a, int b) { return !b ? a : Gcd (b, a % b); }
    bool J ()
    {
        int N, M, x = 0, y; rg int i;
        read (N), read (M);
        for (i = 1; i <= N; ++ i) read (y), x = Gcd (x, abs (y));
        if (N == 1) return y == M;
        if (!x) return !M; return !(abs (M) % x);
    }
    std :: string Name = "det", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int T; read (T);
        for (; T; -- T) printf (J () ? "Y
    " : "N
    ");
        return 0;
    }

    T2

    /*
       T2
       分治
    */
    #include <iostream>
    #include <cstdio>
    typedef long long LL; LL mo;
    #define rg register
    inline void read (LL &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    struct D { LL x, y; D (LL a = 0, LL b = 0) : x (a), y (b) {} };
    std :: string Name = "seq", _I = ".in", _O = ".out";
    #ifdef WIN32
    #define PLL "%I64d"
    #else
    #define PLL "%lld"
    #endif
    inline void cmax (LL &a, LL b) { if (b > a) a = b; }
    inline void cmin (LL &a, LL b) { if (b < a) a = b; }
    D Dfs (LL n, LL l, LL r, LL x, LL y)
    {
        if (x > n || l > r) return D (0, 0);
        if (l == 1 && r == n) 
        {
            cmax (x, 1LL), cmin (y, n); LL s;
            if ((x + y) % 2 == 0) s = ((x + y) / 2) % mo * ((y - x + 1) % mo) % mo;
            else s = ((x + y) % mo) * ((y - x + 1) / 2 % mo) % mo;
            return D (s % mo, y - x + 1);
        }
        LL m = (n + 1) >> 1; D t, p;
        if (r <= m) 
        { t = Dfs (m, l, r, x / 2 + 1, (y + 1) / 2); return D ((t.x * 2 - t.y) % mo, t.y); }
        else if (l > m) 
        { t = Dfs (n - m, l - m, r - m, (x + 1) / 2, y / 2); return D (t.x * 2 % mo, t.y); }
        else 
        {
            t = Dfs (m, l, m, x / 2 + 1, (y + 1) / 2);
            p = Dfs (n - m, 1, r - m, (x + 1) / 2, y / 2);
            return D ((t.x * 2 - t.y + p.x * 2) % mo, (t.y + p.y) % mo);
        }
    }
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        LL N, M, l, r, u, v; read (N), read (M), read (mo); rg int i;
        for (i = 1; i <= M; ++ i)
        {
            read (l), read (r), read (u), read (v);
            printf (PLL"
    ", (Dfs (N, l, r, u, v).x + mo) % mo);
        }
        return 0;
    }

    T3

    /*
        T3
        树形dp
    */
    #include <iostream>
    #include <cstdio>
    #define Max 100010
    typedef long long LL;
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    struct E { E *n; int v; } *list[Max], pool[Max << 1], *Ta = pool;
    inline void In (int u, int v) 
    { ++ Ta, Ta->v = v, Ta->n = list[u], list[u] = Ta; }
    int lca[Max][20], _n[Max], c[Max][20], f[Max][20], _s[Max]; LL s;
    void Dfs_1 (int n, int F)
    {
        lca[n][0] = F, _s[n] = 1; rg int i, v;
        for (i = 1; i <= 16; ++ i) 
            lca[n][i] = lca[lca[n][i - 1]][i - 1];
        for (E *e = list[n]; e; e = e->n)
            if ((v = e->v) != F) Dfs_1 (v, n), _s[n] += _s[v];
    }
    void Dfs (int n, int F)
    {    
        rg int i, v, j;
        for (E *e = list[n]; e; e = e->n)
            if ((v = e->v) != F) _n[n] = v, Dfs (v, n);
        for (i = 0; i <= 16; ++ i)
            s += _s[v = lca[n][i]] - _s[_n[v]], ++ c[v][i], ++ f[v][i];
        for (i = 1; i <= 16; ++ i)
            for (j = 0; j < i; ++ j)
                s += LL (c[n][i] + f[n][i]) * LL (_s[v = lca[n][j]] - _s[_n[v]]), c[v][j] += c[n][i], f[v][j] += f[n][i] + c[n][i];
    }
    std :: string Name = "bitcount", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
         int N; read (N); int x, y; rg int i, j;
        for (i = 1; i < N; ++ i)
            read (x), read (y), In (x, y), In(y, x);
        Dfs_1 (1, 0); _s[0] = _s[1], _n[0] = 1, Dfs (1, 0);
        std :: cout << s; return 0;
    }

    下午

    0 + 60 + 0 = 60 = rank 26

    T1

    T2

    T3

    20171006

    上午

    100 + 50 + 0 = 150 = rank 14

    T1

    /*
        简直智障
        脑子抽了写个双向链表。。。
    */
    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #define rg register
    #define Max 10009
    char l[Max];
    int _n[Max], _l[Max];
    std :: string Name = "kakutani", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, Len, C; scanf ("%d", &N); rg int i, j;
        for (; N; -- N)
        {
            scanf ("%s", l + 1); Len = strlen (l + 1); _n[0] = 1; C = Len;
            for (i = 1; i <= Len + 1; ++ i) _n[i] = i + 1, _l[i] = i - 1;
            for (i = 1; i <= Len; i = _n[i])
                for (; l[i] == '4' || l[i] == '7' || (l[_l[i]] == '1' && l[i] == '3') || (l[_n[i]] == '3' && l[i] == '1'); ) 
                {    
                    for (; l[i] == '4';) 
                        l[i] = l[_n[i]], _n[i] = _n[_n[i]], _l[_n[i]] = i, _n[_l[i]] = i, -- C;
                    for (; l[i] == '7';)
                        l[i] = l[_n[i]], _n[i] = _n[_n[i]], _l[_n[i]] = i, _n[_l[i]] = i, -- C;
                    for (; l[_n[i]] == '3' && l[i] == '1'; )
                        C -= 2, l[i] = l[_l[i]], _l[i] = _l[_l[i]], _n[_l[i]] = i, _n[i] = _n[_n[i]], _l[_n[i]] = i;
                    for (; l[_l[i]] == '1' && l[i] == '3'; )
                        C -= 2, l[i] = l[_n[i]], _n[i] = _n[_n[i]], _l[_n[i]] = i, _l[i] = _l[_l[i]], _n[_l[i]] = i;                
                }
            if (!C) { puts ("0"); continue; }
            else for (i = 0, C = 0; i <= Len; i = _n[i]) if (l[i] != '') ++ C, putchar (l[i]); 
            putchar ('
    ');
        }
        return 0;
    }

    T2

    T3

    下午

    100 + 0 + 20 = 120 = rank 7

    T1

    T2

    T3

    20171007

    上午

    100 + 30 + 20 = 150 = rank 17

    T1

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 100009
    int c[Max];
    std :: string Name = "del", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, K; read (N), read (K); rg int i, s;
        for (i = 1; i <= N; ++ i) read (c[i]);
        std :: sort (c + 1, c + 1 + N); 
        s = std :: unique (c + 1, c + 1 + N) - c - 1; s = N - s;
           if (K <= s) printf ("%d", N - s); else printf ("%d", N - K);
        return 0;
    }

    T2

    T3

    /*
            T2
            读入优化考场忘判负数挂成20的我也是很棒棒
    */
    #include <iostream>
    #include <cstdio>
    typedef double flo;
    #define Max 15
    int K, N, x, v[Max], s[Max];
    #define rg register
    flo f[(1 << Max)][Max * 7]; bool is[(1 << Max)][Max * 7];
    inline flo max (flo a, flo b) { return a > b ? a : b; }
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    flo Calc (int n, int d)
    {
        if (is[n][d] || d > K) return f[n][d];
        is[n][d] = 1; flo r = Calc (n, d + 1);
        for (rg int i = 0; i < N; ++ i)
            if ((s[i] & n) == s[i]) f[n][d] += max (r, Calc (n | (1 << i), d + 1) + v[i]);
            else f[n][d] += r;
        return f[n][d] /= N;
    }
    std :: string Name = "bonus", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        read (K), read (N); rg int i;
        for (i = 0; i < N; ++ i)
            for (read (v[i]); scanf ("%d", &x) && x; s[i] |= (1 << (x - 1)));
        printf ("%.6lf
    ", Calc (0, 1));
    }

    下午

    100 + 100 + 100 = 300 = rank 1

    T1

    /*
        T1
        找出花色不同的连续的最长的牌
        记其中牌的数量为s
        那么答案即为n - s
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #define rg register
    #define Max 100005
    struct D
    {
        int x, y;
        bool operator < (const D &A) const { return A.x == x ? y < A.y : x < A.x; }
        bool operator == (const D &A) const { return x == A.x && y == A.y; }
    } a[Max];
    inline void read (int &n)
    {
        rg char c = getchar (); bool temp = false;
        for (n = 0; !isdigit (c); c = getchar ()) if (c == '-') temp = true;
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
        if (temp) n = -n;
    }
    inline void cmax (int &a, int b) { if (b > a) a = b; }
    std :: string Name = "card", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, M, r = 0, s = 0; read (N); rg int i, j, k, l;
        for (i = 1; i <= N; ++ i) read (a[i].x), read (a[i].y);
        std :: sort (a + 1, a + N + 1); M = std :: unique (a + 1, a + N + 1) - a - 1;
        for (i = 2, j = 1; i <= M; ++ i)
            if (a[i].x != a[i - 1].x)
            {
                for (r = 0, k = j, l = j; k <= i - 1; ++ k)
                {
                     for (; l < i - 1 && a[l + 1].y - a[k].y < N; ++ l);
                    cmax (r, l - k + 1);
                }
                cmax (s, r), j = i;
            }
        for (r = 0, k = j, l = j; k <= i - 1; ++ k)
        {
            for (; l < i - 1 && a[l + 1].y - a[k].y < N; ++ l);
            cmax (r, l - k + 1);
        }
        cmax (s, r); std :: cout << N - s; return 0;
    }

    T2

    /*
        T2
        记f[x]为x这个数字所表示的子集上次出现的位置
        那么暴力枚举读入的数的子集
        判断计算更新即可
    */
    #include <cstdio>
    #include <iostream>
    #define rg register
    inline void read (int &n)
    {
        rg char c = getchar ();
        for (n = 0; !isdigit (c); c = getchar ());
        for (; isdigit (c); n = n * 10 + c - '0', c = getchar ());
    }
    #define Max 100010
    int f[Max];
    std :: string Name = "test", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        int N, x, y, r; read (N); rg int i, s;
        for (i = 1; i <= N; ++ i)
        {
            read (x), read (y); r = x, s = 0;
            if (f[r] < i - y) ++ s; f[r] = i, r = x & (r - 1);
            for (; r; f[r] = i, r = x & (r - 1)) if (f[r] < i - y) ++ s;
            printf ("%d
    ", s);
        }
        return 0;
    }

    T3

    BZOJ 1179: [Apio2009]Atm

    #include <cstdio>
    #include <stack>
    #include <queue>
    #include <iostream>
    
    #define Max 500900
    
    inline int max (int a, int b)
    {
        return a > b ? a : b;
    }
    
    inline int min (int a, int b)
    {
        return a < b ? a : b;
    }
    
    void read (int &now)
    {
        now = 0;
        register char word = getchar ();
        while (word > '9' || word < '0')
            word = getchar ();
        while (word >= '0' && word <= '9')
        {
            now = now * 10 + word - '0';
            word = getchar ();
        }
    }
    
    struct Edge_Type
    {
        struct Edge
        {
            int to;
            int next;
            int dis;
        } 
        edge[Max];
        
        int Edge_Count;
        int edge_list[Max];
        
        void Add_Edge (int from, int to)
        {
            Edge_Count++;
            edge[Edge_Count].to = to;
            edge[Edge_Count].next = edge_list[from];
            edge_list[from] = Edge_Count;
        }
    };
    
    Edge_Type Graph_1;
    
    Edge_Type Graph;
    
    int point_dis[Max];
    int value[Max];
    
    int N, M;
    
    struct Tarjan_Type
    {
        
        std :: stack <int> Stack;
        
        int number[Max];
        int lowlink[Max];
        int Scc_Count;
        
        int Count;
        
        int scc_number[Max];
        
        void Tarjan_ (int N)
        {
            for (int i = 1; i <= N; i++)
                if (!number[i])
                    Dfs (i);
        }
        
        void Dfs (int now)
        {
            Count++;
            number[now] = Count;
            lowlink[now] = Count;
            Stack.push (now);
            for (int i = Graph_1.edge_list[now]; i; i = Graph_1.edge[i].next)
                if (!number[Graph_1.edge[i].to])
                {
                    Dfs (Graph_1.edge[i].to);
                    lowlink[now] = min (lowlink[now], lowlink[Graph_1.edge[i].to]);
                }
                else if (!scc_number[Graph_1.edge[i].to])
                    lowlink[now] = min (lowlink[now], number[Graph_1.edge[i].to]);
            if (lowlink[now] == number[now])
            {
                Scc_Count++;
                int res = now + 1;
                while (res != now)
                {
                    res = Stack.top ();
                    Stack.pop ();
                    scc_number[res] = Scc_Count;
                    point_dis[Scc_Count] += value[res];
                }
            }
        }
        
        void Narrow_Point ()
        {
            for (int now = 1; now <= N; now++)
                for (int i = Graph_1.edge_list[now]; i; i = Graph_1.edge[i].next)
                    if (scc_number[now] != scc_number[Graph_1.edge[i].to])
                        Graph.Add_Edge (scc_number[now], scc_number[Graph_1.edge[i].to]); 
        }
    };
    
    
    Tarjan_Type Make;
    
    struct Spfa_Type
    {
        int distance[Max];
        
        std :: queue <int> Queue;
        bool visit[Max];
        
        int S;
        
        void Do_Spfa (int S)
        {
            Queue.push (S); 
            visit[S] = true;
            int now;
            distance[S] = point_dis[S];
            while (!Queue.empty ())
            {
                now = Queue.front ();
                Queue.pop ();  
                visit[now] = false;
                for (int i = Graph.edge_list[now]; i; i = Graph.edge[i].next)
                    if (distance[Graph.edge[i].to] < distance[now] + point_dis[Graph.edge[i].to])
                    {
                        distance[Graph.edge[i].to] = distance[now] + point_dis[Graph.edge[i].to];
                        if (!visit[Graph.edge[i].to])
                        {
                            Queue.push (Graph.edge[i].to);
                            visit[Graph.edge[i].to] = true; 
                        }
                    }
            }
        }
    };
    
    Spfa_Type Spfa;
    int S, P;
    std :: string Name = "save", _I = ".in", _O = ".out";
    int main (int argc, char *argv[])
    {
        freopen ((Name + _I).c_str (), "r", stdin);
        freopen ((Name + _O).c_str (), "w", stdout);
        read (N);
        read (M);
        int x, y;
        for (int i = 1; i <= M; i++)
        {
            read (x);
            read (y);
            Graph_1.Add_Edge (x, y); 
        }
        for (int i = 1; i <= N; i++)
            read (value[i]);
        Make.Tarjan_ (N);
        Make.Narrow_Point ();
        read (S);
        read (P);
        Spfa.Do_Spfa (Make.scc_number[S]);
        int Answer = 0;
        for (int i = 1; i <= P; i++)
        {
            read (x);
            Answer = max (Answer, Spfa.distance[Make.scc_number[x]]);
        }  
        printf ("%d", Answer);
        return 0;
    }
  • 相关阅读:
    游泳池 (Standard IO)
    Antimonotonicity (Standard IO)
    开花 (Standard IO)
    Wild Number (Standard IO)
    数码问题 (Standard IO)
    输油管道 (Standard IO)
    猴子摘桃 (Standard IO)
    二叉树 (Standard IO)
    iis运行asp.net页面提示“服务器应用程序不可用”的解决办法_.NET.
    SVN安装配置与使用
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/7639777.html
Copyright © 2011-2022 走看看