Educational Codeforces Round 84 (Rated for Div. 2)
A. Sum of Odd Integers
Meaning of the questions : ask \ (n \) can be expressed as \ (k \) different odd sum.
Analysis : First, \ (n-\) and \ (K \) parity must be consistent; second determination at \ (n-\) is less than \ (1 + 3 + 5 + \ cdots + (2k-1) = k ^ 2 \) .
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define eps 1e-3
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll t, n, k, a[SIZE];
int main() {
io(); cin >> t;
while (t--) {
cin >> n >> k;
if (n < k * k || (n - k) % 2) cout << "NO\n";
else cout << "YES\n";
}
}
B. Princesses and Princes
Meaning of the questions : questions face long ah do not write.
Analysis : Piggy just fine.
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
vector<int> vec[SIZE];
vector<int> vis;
int n, t;
int main() {
io(); cin >> t;
rep(ii, 1, t) {
cin >> n;
vis.clear(); vis.resize(n + 1);
int tp = 0, to = 0;
rep(i, 1, n) {
bool f = true;
int k; cin >> k;
vec[i].resize(k);
rep(j, 0, (k - 1)) cin >> vec[i][j];
for (auto j : vec[i]) {
if (!vis[j]) {
vis[j] = true; f = false;
++tp; break;
}
}
if (f) to = i;
}
if (tp == n) cout << "OPTIMAL\n";
else {
cout << "IMPROVE\n";
cout << to << ' ';
rep(i, 1, n) {
if (vis[i]) continue;
cout << i << '\n';
break;
}
}
}
}
C. Game with Chips
The meaning of problems : \ (n-\ Times m \) has a grid of FIG \ (K \) pawn, coordinates \ ((sx_i, sy_i) \) , each piece has a corresponding point coordinates go through \ ((fx_i, fy_i) \) . Now you have the most \ (2nm \) times the opportunity to move each piece can be moved as a whole (if a pawn reaches the boundary will not move, the pieces can overlap) to a mobile four directions in a unit of a given kinds of programs can make each piece must pass through to reach the point.
Analysis : We will direct all the pieces are moved to the top left corner, then \ (S \) shaped to traverse the board.
#include <bits/stdc++.h>
#define SIZE 210
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int n, m, k;
string s;
struct Point {
int x, y;
}p[SIZE];
int main() {
io(); cin >> n >> m >> k;
rep(i, 1, (k + k)) cin >> p[i].x >> p[i].y >> p[i].x >> p[i].y;
rep(i, 1, (n - 1)) s.push_back('U');
rep(i, 1, (m - 1)) s.push_back('L');
int f = 1;
rep(i, 1, n) {
rep(j, 1, (m - 1)) {
if (f) s.push_back('R');
else s.push_back('L');
}
s.push_back('D');
f ^= 1;
}
cout << s.length() << '\n' << s;
}
D. Infinite Path
The meaning of problems : Given a \ (1,2, \ cdots, n \) arranged \ (P_i \) , the position \ (I \) staining \ (C_i \) . Defines an endless path means: there is an infinite sequence \ (I, P [I], P [P [I]], ... P ^ {(n-)} [P [I]] \) , the sequences corresponding to the same color for each position; redefinition \ (K \) th iterative means: for each position \ (I \) , for \ (K \) after iterations resulting sequence (i.e., \ (I \ ) iterations \ (P [I] \) , then the iteration is \ (P [P [I]] \ cdots \) ). After asking at least a few bands iteration, there is at least one endless path.
Analysis : First, because \ (P \) is arranged, therefore, if the \ ((i, p [i ]) \) building side, will get a by a plurality of directional rings of FIG therefore the key to this problem lies in a large ring under what circumstances would separate into small rings. Wherein the ring has assumed a \ (m \) points, starting from a ring \ (S \) departing performed \ (K \) after the iterations, it becomes a loop set point \ ((s + CK) \% m (C \ in the Z) \) (each iteration corresponding to a point \ (I \) to move \ (P [I] \) ). Noting that if \ (k \) instead of \ (m \) factor, then in the same sense than the ring will not split; if \ (k \) is \ (m \) factor and \ (pk = m \) then the ring will split into \ (K \) th from the \ (P \) dots constituting the ringlet. We are therefore \ (K \) of the split ring for each factor can be determined whether the same color.
Since the title given \ (K \ Leq 2E5 \) , thus the maximum number of a factor of no more than \ (160 \) , so we can \ (O (160n) \) simulate this process.
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define eps 1e-3
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
int t, n, ans;
int p[SIZE], c[SIZE];
int main() {
io(); cin >> t;
rep(ii, 1, t) {
cin >> n; ans = n;
rep(i, 0, (n - 1)) cin >> p[i], --p[i];
rep(i, 0, (n - 1)) cin >> c[i];
rep(i, 0, (n - 1)) {
if (p[i] == -1) continue;
vector<int> vec;
for (int j = i; p[j] != -1;) {
vec.emplace_back(c[j]);
int to = p[j];
p[j] = -1;
j = to;
}
rep(j, 1, vec.size()) {
if (vec.size() % j) continue;
rep(s, 0, (j - 1)) {
bool f = true;
for (int k = s; k < vec.size(); k += j) {
if (vec[k] != vec[s]) {
f = false;
break;
}
}
if (f) {
ans = min(ans, j);
break;
}
}
}
}
cout << ans << '\n';
}
}
E. Count The Blocks
The meaning of problems : Statistics \ (0,1,2, \ cdots, 10 ^ -1 \ {n}) number of consecutive sections of different lengths in all figures. For example, \ (0111223 \) have \ (2 \) length of \ (1 \) range, \ (1 \) segment length \ (2 \) range, \ (1 \) segment length \ ( 3 \) range. (If the number is less than \ (\) n bits need to add leading zeros)
Analysis : find the law! \ (A [. 1] = 10, A [2] = 180 [, A [. 3] = 2610., A [I] = 20a [-I. 1] -100A [I-2] (I>. 3) \) .
#include <bits/stdc++.h>
#define SIZE 300010
#define rep(i, a, b) for (long long i = a; i <= b; ++i)
#define int long long
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
const int P = 998244353;
int n, a[SIZE];
signed main() {
io(); n = 300000ll;
a[0] = 10ll; a[1] = 180ll; a[2] = 2610ll;
rep(i, 3, n) a[i] = ((20ll * a[i - 1] - 100ll * a[i - 2]) % P + P) % P;
cin >> n;
for (int i = n; i; --i) cout << a[i - 1] % P << ' ';
}