1. 程式人生 > >QBXT 2017GoKing problems 補完計劃

QBXT 2017GoKing problems 補完計劃

sort n) inf 可能 ret photo con 枚舉 預處理

20171001

上:

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

T3

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\n", 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\n", 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\n", a[0][1]);
    }
}

QBXT 2017GoKing problems 補完計劃