QBXT 2017GoKing problems 补完计划
Posted ZlycerQan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QBXT 2017GoKing problems 补完计划相关的知识,希望对你有一定的参考价值。
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 补完计划的主要内容,如果未能解决你的问题,请参考以下文章