Today, I finally got the official data, and I had a full-on.
Day 1 T1 Toy
Deal with the positive and negative number of the minus-minus to take the mold to mess up just fine.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace Std;int read () { int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 100010int N, q;struct Toy {int tp; char s[15];} ts[maxn];int Main () {freopen ("toy.in", "R", stdin); Freopen ( "Toy.out", "w", stdout); n = read (); Q = Read (); for (int i = 0; i < n; i++) { int t = read (); scanf ("%s", Ts[i]. S); if (!t) ts[i].tp = 1; else TS[I].TP =-1; } int p = 0; while (q--) { int a = read (), B = Read (); if (a) a = 1; else A =-1; p + = A * TS[P].TP * b; p = (p% n + N)% n; } printf ("%s\n", Ts[p]. S); return 0;}
Day 1 T2 Running
The
is inspired by the special points "chain" and "S constant 1" and "T constant 1", we found that each chain [Si, Ti] can be divided into [Si, ci] and [CI, Ti] Two, and then for a all observable chain [ci, Ti] will all Wi minus depth is a Fixed value, for the [Si, Ci] portion of all Wi plus depth is a fixed value. So the tree chain split and then hit the marker statistics just fine.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace Std;int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 300010#define maxm 600010#define maxs 12000010int N, Q, M, HEAD[MAXN], NEXT[MAXM], TO[MAXM], w[maxn];struct P layer {int S, T, C; Player () {} player (int _, int __): s (_), T (__) {}} ps[maxn];void Addedge (int a, int b) {To[++m] = b; next[m] = head [A]; Head[a] = m; Swap (A, b); TO[++M] = b; NEXT[M] = Head[a]; Head[a] = m; return;} int FA[MAXN], DEP[MAXN], SIZ[MAXN], SON[MAXN], TOP[MAXN], POS[MAXN], PID[MAXN], clo;void build (int u) {siz[u] = 1; for (int e = head[u]; e; e = next[e]) if (to[e]! = Fa[u]) {fa[to[e]] = u; Dep[to[e]] = Dep[u] + 1; Build (To[e]); Siz[u] + = Siz[to[E]]; if (Siz[son[u]] < Siz[to[e]]) son[u] = To[e]; } return; void Gett (int u, int tp) {Top[u] = TP; Pid[++clo] = u; pos[u] = CLO; if (Son[u]) Gett (Son[u], TP); for (int e = head[u]; e; e = next[e]) if (to[e]! = Fa[u] && to[e]! = Son[u]) Gett (To[e], to[e]); return;} int LCA (int a, int b) {int f1 = Top[a], F2 = top[b]; while (f1! = F2) {if (Dep[f1] < DEP[F2]) swap (F1, F2), swap (A, b); A = Fa[f1]; F1 = Top[a]; } return Dep[a] < Dep[b]? A:B;} struct Info {int C, FIR[MAXN], Aft[maxs], VAL[MAXS]; void Clear () {c = 0; memset (fir, 0, sizeof (FIR)); return; } void Addinfo (int x, int v) {Val[++c] = v; aft[c] = fir[x]; fir[x] = c; return; }} Add, Del;int tot[maxn<<1], ans[maxn];void process (int x, int t, int a, int v) {int f = top[a]; while (f! = Top[t]) {Add. Addinfo (Pos[f], V); Del. Addinfo (Pos[a], V); A = Fa[f]; f = top[a]; } ADD.addinfo (Pos[t], V); Del. Addinfo (Pos[a], V); return;} int main () {freopen ("running.in", "R", stdin), Freopen ("Running.out", "w", stdout); n = read (); Q = Read (); for (int i = 1; i < n; i++) {int a = read (), B = Read (); Addedge (A, b); } for (int i = 1; I <= n; i++) W[i] = read (); for (int i = 1; I <= Q; i++) {int s = read (), t = Read (); Ps[i] = Player (s, t); } build (1); Gett (1, 1); for (int i = 1; I <= n; i++) w[i] = Dep[i]; Add.clear (); Del.clear (); memset (tot, 0, sizeof (TOT)); for (int i = 1; I <= Q; i++) {ps[i].c = LCA (PS[I].S, ps[i].t); Process (I, PS[I].C, ps[i].t, Dep[ps[i].s]-dep[ps[i].c]-dep[ps[i].c]); } for (int i = 1, i <= N; i++) {for (int e = add.fir[i]; e = add.aft[e]) {int v = add.val[e] + N tot[v]++; } int u = pid[i]; Ans[u] + = Tot[w[u]+n]; for (int e = del.fir[i], e; e = del.aft[e]) {int v = Del.val[e] + N; tot[v]--; }} for (int i = 1; I <= n; i++) w[i] + = (Dep[i] << 1); Add.clear (); Del.clear (); memset (tot, 0, sizeof (TOT)); for (int i = 1; I <= Q; i++) process (i, PS[I].C, Ps[i].s, Dep[ps[i].s]); for (int i = 1, i <= N; i++) {for (int e = add.fir[i]; e; e = add.aft[e]) {int v = add.val[e]; tot[v]++; } int u = pid[i]; Ans[u] + = Tot[w[u]]; for (int e = del.fir[i]; e; e = del.aft[e]) {int v = del.val[e]; tot[v]--; }} for (int i = 1; I <= Q; i++) if (w[ps[i].c] = = Dep[ps[i].s]) ans[ps[i].c]--; for (int i = 1; I <= n; i++) printf ("%d%c", Ans[i], I < n? ': ' \ n '); return 0;}
Day 1 T3 Classroom
I think of the problem in the examination room, but because the adjacency matrix in the edge of forgetting to remember Min is SB ....
Set F[0][I][J] indicates that the previous I request used J, the last one not taken the minimum desired distance; F[1][i][j] indicates that the first I request uses J Bar, the last one takes the minimum desired distance. Then, because each side of the line is independent, the transfer is directly multiplied by the probability of accumulation on the good.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace Std;int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 2010#define maxv 310#define oo 1000000000int N, M, V, E, c[maxn], D[MAXN], D[MAXN][MAXN];d ouble P[MAXN], f[2] [MAXN] [Maxn];void Up (double& A, double b) {a = min (a, b); return;} int main () {freopen ("classroom.in", "R", stdin), Freopen ("Classroom.out", "w", stdout); n = read (); m = read (); v = read (); E = Read (); for (int i = 1; I <= n; i++) C[i] = read (); for (int i = 1; I <= n; i++) D[i] = read (); for (int i = 1; I <= n; i++) scanf ("%lf", &p[i]); for (int i = 1; I <= v; i++) {d[i][i] = 0; for (int j = i + 1; j <= V; j + +) D[i][j] = d[j][i] = oo; } for (int i = 1; I <= e; i++) {int a = read (), B = Read (), C = Read (); D[a][b] = min (d[a][b], c); D[b][a] = min (D[b][a], c); } for (int k = 1, k <= v; k++) for (int i = 1; I <= v; i++) for (int j = 1; J <= V; j + +) D[i][j] = min (D[i][j], d[i][k] + d[k][j]); for (int i = 0, I <= N; i++) for (int j = 0; J <= M; j + +) F[0][i][j] = f[1][i][j] = 1e9; F[0][0][0] = 0.0; for (int i = 0; l <= N; i++) for (int j = 0; J <= min (i + 1, m); j + +) {double P = p[i], NP = p[i+1] , p1 = 1.0-p, np1 = 1.0-NP; Up (F[0][i+1][j], f[0][i][j] + d[c[i]][c[i+1]); Up (F[1][i+1][j+1], F[0][i][j] + NP * D[c[i]][d[i+1]] + NP1 * d[c[i]][c[i+1]]); Up (F[0][i+1][j], f[1][i][j] + P * d[d[i]][c[i+1]] + p1 * d[c[i]][c[i+1]]); Up (F[1][i+1][j+1], f[1][i][j] + p * NP * D[D[I]][D[I+1]] + p * NP1 * d[d[i]][c[i+1]] + p1 * NP * d[c[i]][d[i+1]] + p1 * NP 1 * d[c[i]][c[i+1]]); } double ans = 1e9; for (int i = 0; I <= m; i++) up (ans, min (f[0][n][i], f[1][n][i])); printf ("%.2lf\n", ans); return 0;}
Day 2 T1 problem
The recursive method is used to find the combined number and the real-time modulus K.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace Std;int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 2010int C[2][MAXN], F[maxn][maxn];int main () {freopen ("problem.in", "R", stdin) freopen ("Problem.out", "W" , stdout); int size = 2000; BOOL cur = 0; int T = Read (), k = Read (); for (int i = 0; I <= size; i++, cur ^= 1) {c[cur][0] = 1; C[cur][i] = 1; for (int j = 1; j < I; j + +) C[cur][j] = (C[cur^1][j-1] + c[cur^1][j])% K; for (int j = 0; J <= I; j + +) {F[i][j] = (! C[CUR][J]); int t = 0; if (j) f[i][j] + = f[i][j-1], t++; if (J <= i-1) f[i][j] + = F[i-1][j], t++; if (t = = 2 && i && j) f[i][j]-= f[i-1][j-1]; }} while (t--) {int n = read (), M = Read (); printf ("%d\n", F[n][min (n,m)]); } return 0;}
Day 2 T2 Earthworm
Inspired by the data of q = 0, which does not increase the length of the earthworm, we find that the length of the two earthworms at each threshold must be monotonically reduced, so that O (n) can be done.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace Std;int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 100010#define MAXM 7100010#define LL long longint N, M, q, u, V, T, A[maxn], B[MAXM], C[maxm], LB, RB, LC, RC , ANS[MAXM], Cnt;bool cmp (int a, int b) {return a > B;} void process (int tmp, int i, int len) {int nb = (LL) tmp * u/v, NC = TMP-NB; B[++RB] = nb-len-q; C[++RC] = nc-len-q; if (i% t = = 0) ans[++cnt] = tmp; return;} int main () {freopen ("earthworm.in", "R", stdin), Freopen ("Earthworm.out", "w", stdout); n = read (); m = read (); Q = Read (); U = Read (); v = read (); t = read (); for (int i = 1; I <= n; i++) A[i] = read (); Sort (A + 1, a + n + 1, CMP);//for (int i = 1; I <= N;i++) printf ("%d%c", A[i], I < n? ': ' \ n '); LB = 1; RB = 0; LC = 1; rc = 0; int PA = 1, len = 0; for (int i = 1; I <= m; i++, len + = q) {int A, b, C; A = (PA <= n)? A[PA] + len:-1; b = (lb <= rb)? B[LB] + len:-1; c = (LC <= RC)? C[LC] + len:-1; if (a >= b && a >= c) {pa++; Process (A, I, Len); } else if (b >= a && b >= c) {lb++; Process (b, I, Len); } else {lc++; Process (c, I, Len); }} for (int i = 1; I <= cnt; i++) printf ("%d%c", Ans[i], I < CNT? ': ' \ n '); if (!cnt) Putchar (' \ n '); CNT = 0; for (int i = 1; I <= n + m; i++) {int A, b, C; A = (PA <= n)? A[PA] + len:-1; b = (lb <= rb)? B[LB] + len:-1; c = (LC <= RC)? C[LC] + len:-1; if (a >= b && a >= c) {pa++; if (i% t = = 0) ANS[++CNT] = A; } else if (b >= a && b >= c) {lb++; if (i% t = = 0) ans[++cnt] = b; } else {lc++; if (i% t = = 0) ans[++cnt] = C; }} for (int i = 1; I <= cnt; i++) printf ("%d%c", Ans[i], I < CNT? ': ' \ n '); if (!cnt) Putchar (' \ n '); return 0;}
Day 2 T3 Angrybirds
Pressure DP, set F[s] means the minimum number of parabolic lines needed to kill the set S pig, the first pig to be found without being killed, and the other pig, two points to determine a parabola (0, 0), and then transfer to the current set and parabola through the collection of pigs set. Note that each parabolic pass through the pig's collection can be pretreated.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm> #include <cmath>using namespace Std;int read () {int x = 0, f = 1; char c = GetChar (); while (!isdigit (c)) {if (c = = '-') f =-1; c = GetChar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = GetChar ();} return x * f;} #define MAXN 23#define maxs 362154const Double eps = 1e-6;struct point {double x, y; Point () {}-point (Double _, double __): X (_), Y (__) {} BOOL operator < (const point& t) const {return x! = T. X? X < t.x:y < T.y; }} ps[maxn];int F[maxs], Ls[maxn][maxn];bool on (double A, double b, point P) {return fabs (A * p.x * p.x + b * p.x-p. y) <= EPS;} void up (int& a, int b) {if (a < 0) A = b; else a = min (a, b); return;} int main () {freopen ("angrybirds.in", "R", stdin), Freopen ("Angrybirds.out", "w", stdout); int T = read (); while (t--) {int n = read (); Read (); for (int i = 0; i < n; i++) scanf ("%lf%lf", &ps[i].x, &PS[I].Y); Sort (PS, PS + N); Memset (F,-1, sizeof (f)); memset (LS, 0, sizeof (LS)); F[0] = 0; for (int i = 0; i < n; i++) for (int j = 0; J < N; j + +) if (i! = j) {Double x1 = ps[i].x, y1 = P S[i].y, x2 = ps[j].x, y2 = ps[j].y; Double b = (x1 * X1 * y2-x2 * x2 * y1)/(x1 * X1 * x2-x2 * x2 * x1); Double A = (Y1-b * x1)/(x1 * x1); if (a >= 0.0) continue; int S = 0; for (int k = 0; k < n; k++) if (((S >> K & 1) ^ 1) && on (A, B, Ps[k])) S |= (1 <& Lt k); LS[I][J] = S; } int all = (1 << N)-1; for (int S = 0; S <= All; s++) if (F[s] >= 0) for (int j = 0; J < N; j + +) if ((S >> J & 1) ^ 1) {int TS = S | (1 << j); Up (F[ts], F[s] + 1); for (int i = j + 1; i < n; i++) if ((TS >> I & 1) ^ 1) up (F[ts | ls[i][j], f[s] + 1); Break } printf ("%d\n", F[all]); } return 0;}
Why this NOIP is the second problem most difficult TAT
NOIP2016 Topic Integration