Educational Codeforces Round 163 A-E
A. Special Characters
构造。
形如
时间复杂度:
#include <bits/stdc++.h>
using namespace std;
#define cctie ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(), x.end()
#define ALL(x) x.begin() + 1, x.end()
using i64 = long long;
void solve() {
int n;
cin >> n;
if (n & 1) {
cout << "NO\n";
} else {
cout << "YES\n";
string ans;
for (int i = 0; i < n / 2; i++) {
ans.push_back('A' + i);
ans.push_back('A' + i);
}
cout << ans << '\n';
}
}
void prework() {
}
int main() {
cctie;
prework();
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
B. Array Fix
枚举/贪心。
枚举:能执行操作的一定是两位数,且该操作一定会使被操作数分裂成两个个位数,则当我们对第
贪心:当第
时间复杂度:枚举
#include <bits/stdc++.h>
using namespace std;
#define cctie ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(), x.end()
#define ALL(x) x.begin() + 1, x.end()
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
bool ans = false;
for (int i = 0; i <= n; i++) {
vector<int> b;
for (int j = 1; j <= n; j++) {
if (j <= i && a[j] >= 10) {
b.push_back(a[j] / 10);
b.push_back(a[j] % 10);
} else {
b.push_back(a[j]);
}
}
int m = b.size();
bool f = true;
for (int i = 1; i < m; i++) {
if (b[i] < b[i - 1]) {
f = false;
}
}
if (f) {
ans = true;
}
}
if (ans) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
void prework() {
}
int main() {
cctie;
prework();
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
C. Arrow Path
搜索 。
按题中的行动方式进行
时间复杂度:
#include <bits/stdc++.h>
using namespace std;
#define cctie ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(), x.end()
#define ALL(x) x.begin() + 1, x.end()
using i64 = long long;
void solve() {
int n;
cin >> n;
vector<vector<char>> a(3, vector<char>(n + 1));
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
vector<vector<bool>> st(3, vector<bool>(n + 1));
queue<array<int, 2>> q;
q.push({1, 1});
st[1][1] = true;
vector<int> dx = {-1, 0, 0, 1}, dy = {0, 1, -1, 0};
auto is_legal = [&](int x, int y)->bool {
return 1 <= x && x <= 2 && 1 <= y && y <= n;
};
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (is_legal(nx, ny)) {
if (a[nx][ny] == '<') {
ny--;
} else {
ny++;
}
if (!st[nx][ny]) {
st[nx][ny] = true;
q.push({nx, ny});
}
}
}
}
if (st[2][n]) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
void prework() {
}
int main() {
cctie;
prework();
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
D. Tandem Repeats?
枚举/动态规划。
枚举:考虑答案能否为
动态规划:
时间复杂度:
#include <bits/stdc++.h>
using namespace std;
#define cctie ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(), x.end()
#define ALL(x) x.begin() + 1, x.end()
using i64 = long long;
void solve() {
string s;
cin >> s;
int n = s.size(), ans = 0;
for (int l = 1; l <= n / 2; l++) {
int cnt = 0;
for (int i = 0, j = 0; i + l < n; i++) {
if (s[i] == s[i + l] || s[i] == '?' || s[i + l] == '?') {
cnt++;
if (cnt == l) {
ans = l * 2;
break;
}
} else {
cnt = 0;
}
}
}
cout << ans << '\n';
}
void prework() {
}
int main() {
cctie;
prework();
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
E. Clique Partition
贪心、构造。
考虑每一个团皆由连续的点集所构成,因为这样能使
时间复杂度:
#include <bits/stdc++.h>
using namespace std;
#define cctie ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(), x.end()
#define ALL(x) x.begin() + 1, x.end()
using i64 = long long;
void solve() {
int n, k;
cin >> n >> k;
int col = 0;
vector<int> a(n + 1), c(n + 1);
iota(ALL(a), 1);
for (int i = 1; i <= n; i += k) {
int j = min(i + k - 1, n), h = i + j >> 1;
reverse(a.begin() + i, a.begin() + h + 1);
reverse(a.begin() + h + 1, a.begin() + j + 1);
fill(c.begin() + i, c.begin() + j + 1, ++col);
}
for (int i = 1; i <= n; i++) {
cout << a[i] << " \n"[i == n];
}
cout << col << '\n';
for (int i = 1; i <= n; i++) {
cout << c[i] << " \n"[i == n];
}
}
void prework() {
}
int main() {
cctie;
prework();
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
分类:
题解 / Codeforces
标签:
题解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧