Codeforces Round #699 (Div. 2)
Codeforces Round #699 (Div. 2)
A Space Navigation
int main() {
IOS;
for (cin >> _; _; --_) {
int x, y; cin >> x >> y; string s; cin >> s;
for (auto c : s)
if (x > 0 && c == 'R') --x;
else if (x < 0 && c == 'L') ++x;
else if (y > 0 && c == 'U') --y;
else if (y < 0 && c == 'D') ++y;
cout << (x || y ? "NO\n" : "YES\n");
}
return 0;
}
B New Colony
按照题意模拟石头的下落过程, 反正数据小
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> k; VI h(n); m = -1;
for (auto &i : h) cin >> i;
rep (i, 1, k) {
rep (j, 1, n - 1)
if (h[j] > h[j - 1]) { ++h[j - 1], m = j; break; }
else if (j == n - 1) { m = -1; break; }
if (m == -1) break;
}
cout << (m > -1 ? m : -1) << '\n';
}
return 0;
}
C Fence Painting
弄个两个集合, 一个是必须要涂一次颜色i的集合, 一种是颜色i随便涂的集合
把不能图的颜色放在将涂这两个集合内之前的模板就行
int a[N], b[N], c[N], p[N], d[N];
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> m; vector<VI> col(n + 1);
rep(i, 1, n) cin >> a[i], p[i] = 0;
rep(i, 1, n) {
cin >> b[i];
if (a[i] == b[i]) p[b[i]] = i;
else col[b[i]].pb(i);
}
rep(i, 1, m) {
cin >> c[i];
if (!col[c[i]].empty()) {
while (!col[0].empty()) d[col[0].back()] = col[c[i]].back(), col[0].pop_back();
d[i] = col[c[i]].back(); col[c[i]].pop_back(); p[c[i]] = d[i];
} else if (p[c[i]]) {
while (!col[0].empty()) d[col[0].back()] = p[c[i]], col[0].pop_back();
d[i] = p[c[i]];
}
else col[0].pb(i);
}
bool f = 1;
for (auto& i : col) if (!i.empty()) f = 0;
if (!f) { cout << "NO\n"; continue; }
cout << "YES\n"; rep(i, 1, m) cout << d[i] << ' '; cout << '\n';
}
return 0;
}
D AB Graph
奇数直接在两个点之前反复跳即可
偶数要找3个点, d[a][b] = d[b][c]
其他无解
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> k; bool f = 0;
rep (i, 1, n) cin >> d[i] + 1;
rep (i, 1, n) rep (j, i + 1, n) if (d[i][j] == d[j][i] && !f) {
cout << "YES\n"; cout << i << ' ';
rep (t, 1, k) cout << (t & 1 ? j : i) << ' ';
cout << '\n'; f = 1;
}
if (f) continue;
if (k & 1) {
cout << "YES\n"; cout << 1 << ' ';
rep (i, 1, k) cout << (i & 1 ? 2 : 1) << ' ';
cout << '\n';
}
else if (n < 3) { cout << "NO\n"; continue; }
else {
cout << "YES\n"; int a = 0, b = 1, c = 2;
while (d[a + 1][b + 1] != d[b + 1][c + 1]) a = (a + 1) % 3, b = (b + 1) % 3, c = (c + 1) % 3;
//既然到了这里, 那么就不存在 d[a][b] == d[b][a], 那么 d[a][b] = d[b][c], 那么必然 (d[b][a] = d[c][b]) != (d[a][b] = d[b][c])
vector<int> t = {a + 1, b + 1, c + 1, b + 1};
rep (i, 0, k) cout << t[(i + (k % 4 == 0)) % 4] << ' '; cout << '\n';
}
}
return 0;
}