"Game link" Click Open link
"Puzzle link" Click Open link
"A" love triangle
"points of thought" in accordance with the search for the triangle can be. Where there is a point \ (i\) that makes \ (f[f[f[i]]]==i\), the answer is yes, otherwise no. Time Complexity \ (O (N) \).
"Code"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
Template <typename t> void Read (T &x) {
x = 0; int f = 1;
char C = GetChar ();
for (;!isdigit (c); c = GetChar ()) if (c = = ") F = f;
for (; IsDigit (c); c = GetChar ()) x = x * + C-' 0 ';
x *= f;
}
Template <typename t> void Write (T x) {
if (x < 0) x = x, Putchar ('-');
if (x > 9) write (X/10);
Putchar (x + ' 0 ');
}
Template <typename t> void Writeln (T x) {
write (x);
Puts ("");
}
int F[MAXN];
int main () {
int n; read (n);
for (int i = 1; I <= n; i++)
read (f[i]);
bool ans = false;
for (int i = 1; I <= n; i++)
ans |= f[f[f[i]] = = i;
if (ans) printf ("yes\n");
else printf ("no\n");
return 0;
}
"B" Hamster Farm
"points of thought" in accordance with the simulation can be. Note that the answer is 0. Time Complexity \ (O (K) \).
"Code"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
Template <typename t> void Read (T &x) {
x = 0; int f = 1;
char C = GetChar ();
for (;!isdigit (c); c = GetChar ()) if (c = = ") F = f;
for (; IsDigit (c); c = GetChar ()) x = x * + C-' 0 ';
x *= f;
}
Template <typename t> void Write (T x) {
if (x < 0) x = x, Putchar ('-');
if (x > 9) write (X/10);
Putchar (x + ' 0 ');
}
Template <typename t> void Writeln (T x) {
write (x);
Puts ("");
}
int main () {
long long n, ans = 0, cnt = 0;
int K, pos = 1; Read (n); Read (k);
for (int i = 1; I <= K; i++) {
long long x; read (x);
Long Long tcnt = n/x;
Long Long tans = tcnt * x;
if (Tans > ans) {
ans = tans;
CNT = tcnt;
pos = i
}
}
cout << pos << ' << cnt << Endl;
return 0;
}
"C" convenient for everybody
The income of each moment of the "idea point" corresponds to the sum of the weights of the interval (in the mode) of the original sequence. The original sequence is multiplied by the prefix and is used to support the query of the interval and. Time Complexity \ (O (N) \).
"Code"
#include <bits/stdc++.h> using namespace std;
const int MAXN = 200005;
Template <typename t> void Read (T &x) {x = 0; int f = 1;
char C = GetChar ();
for (;!isdigit (c); c = GetChar ()) if (c = = ") F = f;
for (; IsDigit (c); c = GetChar ()) x = x * + C-' 0 ';
x *= F;
} template <typename t> void Write (T x) {if (x < 0) x = x, Putchar ('-');
if (x > 9) write (X/10);
Putchar (x% 10 + ' 0 ');
} template <typename t> void Writeln (T x) {write (x);
Puts ("");}
Long Long A[MAXN], SUM[MAXN];
int main () {int n; read (n);
for (int i = 1; I <= n; i++) read (A[i]), A[i + n] = A[i];
for (int i = 1; I <= 2 * n; i++) sum[i] = A[i] + sum[i-1]; int S, F;
Read (s), read (f); Long ans = 0;
int pos = 1;
for (int i = 1; I <= n; i++) {int start = S-i + N;
if (start >= n) start = n;
Long Long tmp = Sum[start + f-s]-sum[start];
if (tmp > ans) {ans = tmp;
pos = i;
} writeln (POS);
return 0; }
"D" Love Rescue
"The main points of thought" sample two, we n\ a group of \ () letters into all the same, only need to string them into a chain from beginning to end, at the cost of \ (n-1\). The letter of the corresponding position of two strings is connected without direction, and the letter of each Unicom block in the graph is changed to the same by the above method. It can be proved that this cost must be the least. Time complexity of \ (O (n+|) s|^2) \), in this subject \ (| s|=26\).
"Code"
#include <bits/stdc++.h> using namespace std;
const int MAXN = 100005;
const int MAXC = 30;
Template <typename t> void Read (T &x) {x = 0; int f = 1;
char C = GetChar ();
for (;!isdigit (c); c = GetChar ()) if (c = = ") F = f;
for (; IsDigit (c); c = GetChar ()) x = x * + C-' 0 ';
x *= F;
} template <typename t> void Write (T x) {if (x < 0) x = x, Putchar ('-');
if (x > 9) write (X/10);
Putchar (x% 10 + ' 0 ');
} template <typename t> void Writeln (T x) {write (x);
Puts ("");}
int n, ans, cnt;
Char S[MAXN], T[MAXN];
Char X[MAXC], Y[MAXC], Q[MAXC];
BOOL USED[MAXC], MP[MAXC][MAXC];
void work (int pos) {Used[pos] = false;
Q[++CNT] = pos + ' a ';
for (int i = 0; I <= i++) if (Used[i] && mp[pos][i]) work (i);
int main () {read (n);
scanf ("\n%s", S + 1);
scanf ("\n%s", T + 1);
for (int i = 1; I <= n; i++) if (S[i]!= t[i]) {mp[s[i]-' a '][t[i '-' a '] = mp[t[i]-' a '][s[i]-' a ' = true; Used[s[i]-' a '] = used[t[i]-' A '] = true;
for (int i = 0; I <= i++) if (Used[i]) {cnt = 0;
Work (i);
for (int j = 2; J <= CNT; j + +) {ans++;
X[ans] = q[j-1];
Y[ans] = Q[j];
Writeln (ANS);
for (int i = 1; I <= ans; i++) printf ("%c%c\n", x[i), Y[i]);
return 0; }
"E" maximize!
"points of thought"
For Query 1, we can easily maintain a sorted original sequence and its prefix and array.
For Query 2, it is not difficult to find that the selected collection must be the maximum value of the current sequence and a collection of the smallest number of elements. The Definition \ (F (i) \) represents the value of the answer when selecting the maximum value for the current sequence and the smallest \ (i\) element. \ (f\) is a single peak function, with the three-point method (can also be) to solve the problem, time complexity (O (QLOGQ) \). Further thinking, we found that for each query 2,\ (F (i) \) to take the optimal value (i\) of the value is monotonous, therefore, use two pointers maintenance answer can be. Time Complexity \ (O (Q) \).
"Code"
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; template <typename t>
void Read (T &x) {x = 0; int f = 1;
char C = GetChar ();
for (;!isdigit (c); c = GetChar ()) if (c = = ") F = f;
for (; IsDigit (c); c = GetChar ()) x = x * + C-' 0 ';
x *= F;
} template <typename t> void Write (T x) {if (x < 0) x = x, Putchar ('-');
if (x > 9) write (X/10);
Putchar (x% 10 + ' 0 ');
} template <typename t> void Writeln (T x) {write (x);
Puts ("");}
int n;
Long double X[MAXN], SUM[MAXN];
Long double aver (int pos) {return (Sum[pos] + x[n])/(pos + 1);} int main () {int T; read (t);
int pos = 0;
while (t--) {int opt; read (opt);
if (opt = 1) read (X[++n]), sum[n] = sum[n-1] + x[n];
else {long double ans = 0;
if (n = = 1) ans = 0;
else {while (pos + 1 <= n-1 && aver (pos + 1) < Aver (POS)) pos++;
Ans = x[n]-aver (POS);
printf ("%.10lf\n", ans);
} return 0; }
"F" Cutlet
"points of thought" an obvious DP approach when recording \ (f_{i,j}\) is said to have reached "at the moment \ (i\), the heated side is heated up (j\) moment" The minimum cost of this state (or the state is not reachable), the transfer is divided into keeping the original or upside down, more obviously, Time Complexity \ (O (n^2) \), unable to pass the subject. Note that \ (k\) is relatively small, the time complexity of (O (NK)) is feasible, consider each section can be turned over and can not turn over the time interval together transfer. It is obvious that the time interval transfer of the surface can not be turned over, and the interval length is (len\), then there is \ (f_{i,j}=f_{i-1,j-len}\).
Consider the transfer of the time interval that can be turned over, obviously, in each of these intervals, we have turned over 2 times, more than the surface is not excellent. Set the current moment to \ (t\), and the interval length is \ (len\). Turn the surface 0 times, and can not turn over the time interval of the same. Turn over 1 times, then have \ (f_{i,j}=min (f_{i,j},min_{k=t-j-len}^{t-j}\{f_{i-1,k}\}+1) \). Turn over 2 times, then have \ (f_{i,j}=min (f_{i,j},min_{k=j-len}^{j}\{f_{i-1,k}\}+2) \). With the monotone queue optimization transfer, we can get the transfer complexity of an equally (O (1) \). Scrolling array, space complexity \ (O (N) \). Time complexity (O NK).
"Code"
#include <bits/stdc++.h> using namespace std;
const int MAXN = 100005;
Template <typename t> void Read (T &x) {x = 0; int f = 1;
char C = GetChar ();
for (;!isdigit (c); c = GetChar ()) if (c = = ") F = f;
for (; IsDigit (c); c = GetChar ()) x = x * + C-' 0 ';
x *= F;
} template <typename t> void Write (T x) {if (x < 0) x = x, Putchar ('-');
if (x > 9) write (X/10);
Putchar (x% 10 + ' 0 ');
} template <typename t> void Writeln (T x) {write (x);
Puts ("");}
int DP[2][MAXN];
struct Humdrumqueue {int L, R, Num[maxn], VAL[MAXN];
void Init () {L = 0;
r =-1;
} void push (int pos, int v) {while (R >= l && v <= val[r]) r--;
Val[++r] = v;
NUM[R] = pos;
} void Pop (int pos) {if (num[l] = = pos) l++;
int get () {return val[l];
} HQ, HP;
int main () {int n, k; Read (n), read (k);
for (int j = 0; J <= N; j +) dp[0][j] = 1e9;
Dp[0][0] = 0;
int last = 0; for (int i = 1; I <= K; i++) {for (int j = 0; J ≪= N;
J + +) dp[1][j] = 1e9; int QL, QR;
Read (QL), read (QR);
for (int j = 0; J <= N; j +) {int tmp = J-(ql-last);
if (TMP >= 0) Dp[1][j] = dp[0][tmp];
for (int j = 0; J <= N; j +) dp[0][j] = 1e9; Hq.init ();
Hp.init ();
for (int j = 0; J <= N; j +) {Hq.push (J, Dp[1][j]);
Hq.pop (J-(QR-QL)-1);
int L = qr-j;
int TL = L-(QR-QL);
if (TL >= 0 && tl <= N) hp.push (TL, DP[1][TL]);
Hp.pop (l + 1);
if (L < 0 | | | L > N) continue;
int tmp = J-(QR-QL);
if (TMP >= 0) Dp[0][j] = dp[1][tmp];
Dp[0][j] = min (Dp[0][j], hp.get () + 1);
Dp[0][j] = min (Dp[0][j], hq.get () + 2);
last = QR;
for (int j = 0; J <= N; j +) dp[1][j] = 1e9;
for (int j = 0; J <= N; j +) {int tmp = J-(2 * n-last);
if (TMP >= 0) Dp[1][j] = dp[0][tmp];
} if (Dp[1][n] >= 1e9) printf ("hungry\n");
else printf ("full\n%d\n", Dp[1][n]);
return 0; }