Educational Codeforces Round 168 (Rated for Div. 2)
1.E. Arranging The Sheep2.C. Team3.C. RationalLee4.B. Preparing Olympiad5.B. Find The Array6.E. Accidental Victory7.A. Learning Languages8.A. k-th divisor9.B. Quasi Binary10.蓝桥杯-地宫取宝11.D. Divide by three, multiply by two12.D. Game With Array13.B. Composite Coloring14.洛谷 P1204 [USACO1.2] 挤牛奶Milking Cows15.洛谷 P3353 在你窗外闪耀的星星16.洛谷 P8818 [CSP-S 2022] 策略游戏17.Educational Codeforces Round 164 (Rated for Div. 2)18.E. Chain Reaction19.Manthan, Codefest 18 (rated, Div. 1 + Div. 2) D. Valid BFS?20.D. Distance in Tree21.D. Multiplication Table22.C. Mixing Water23.B. Greg and Graph24.D. Another Problem About Dividing Numbers25.Acwing 143. 最大异或对26.Acwing 3485. 最大异或和27.C. Checkposts28.E. Lomsat gelral29.D. Powerful array30.D. Deleting Divisors31.Codeforces Round 950 (Div. 3)32.Codeforces Round 951 (Div. 2)33.SuntoryProgrammingContest2024(AtCoder Beginner Contest 357)34.Codeforces Round 952 (Div. 4)35.AtCoder Beginner Contest 35836.B. Modulo Sum37.D. Soldier and Number Game38.AtCoder Beginner Contest 35939.Codeforces Round 954 (Div. 3)40.Codeforces Round 955 (Div. 2, with prizes from NEAR!)41.AtCoder Regular Contest 18042.D - Ghost Ants43.AtCoder Beginner Contest 361)44.Codeforces Round 957 (Div. 3)45.E. Decode
46.Educational Codeforces Round 168 (Rated for Div. 2)
47.B. Parity and Sum48.P1972 [SDOI2009] HH的项链49.Codeforces Round 966 (Div. 3) VP50.https://codeforces.com/contest/2004/problem/B51.C. Splitting Items52.D. Colored Portals53.Codeforces Round 967 (Div. 2)54.D. Determine Winning Islands in Race55.C. Turtle and Good Pairs56.Codeforces Round 970 (Div. 3)(VP)57.G. Sakurako's Task58.Codeforces Round 971 (Div. 4)59.C. Lazy Narek60.B. Regular Bracket Sequence61.C. News Distribution62.B. Karen and Coffee63.G. 2^Sort64.C. Johnny and Another Rating Drop65.A. Greg and Array66.D2. Magic Powder - 267.C. Schedule Management68.C. Constanze's Machine69.C. Soldier and Cards70.C. Berland Regional71.E. Anna and the Valentine's Day Gift72.B. Polo the Penguin and Matrix73.B. Fortune Telling74.C. Powers Of Two75.D. Palindromes Coloring76.C. Phoenix and Towers没有时间参赛 直接补几道简单题吧~
B. Make Three Regions
题意:给一个2行的字符串,有block和其他东西,问把一个位置变成block让联通的部分变成3个部分,有多少种方法
思路:找规律,找所哟符合条件的块即可
void solve(){
int n;
cin >> n;
array<string, 2> s;
cin >> s[0] >> s[1];
int ans = 0;
for (int i = 1; i < n - 1; ++i) {
for (int j = 0; j < 2; ++j) {
if (s[j][i] == '.' && s[j][i - 1] == 'x' && s[j][i + 1] == 'x' &&
s[j ^ 1][i] == '.' && s[j ^ 1][i - 1] == '.' && s[j ^ 1][i + 1] == '.'
) {
ans ++;
}
}
}
cout << ans << '\n';
}
C. Even Positions
题意:给定长度为n的括号字符串,下标1~n,并且所有奇数位置上的字符让自己填。字符串的代价是匹配括号的距离。求所有填充字符的方法中最小的距离。
思路:一眼贪心,首先字符串要合法。在合法的前提下,肯定是如果有左括号就直接填右。如果没有左,就填左。
总结:这个算法的正确性证明比较有趣。 会不会出现按照这个策略填充,会出现到了最后左右括号数量不相等的情况?
void solve(){
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '_') {
if (!cnt) {
cnt ++;
s[i] = '(';
}
else {
s[i] = ')';
cnt --;
}
}
else {
cnt += (s[i] == '(' ? 1 : -1);
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(') {
ans -= i;
}
else {
ans += i;
}
}
cout << ans << '\n';
}
D. Maximize the Root
题意:给定一颗树,每个结点有权值。每次操作可以将以当前结点v的子树中,所有的子节点权值-1,然后v的权值+1。不限操作次数的操作后,root根的编号为1的最大权值是多少?
思路:操作过程中要求结点权值不能为负数,所以结点1的权值增加的幅度,就是树中所有的结点,经过操作后值最小的最大值。于是问题转化为,经过若干次操作后,权值最小的结点,最大是多少。 直接dfs遍历,统计当前子树中权值最小的结点,分两种情况讨论。如果当前结点权值<最小权值结点,则当前结点权值变大,否则不变。
总结:一开始理解错题了,以为权值减小的结点只跟与当前结点直接相连的子节点有关。后来tc过不去才发现是子树中所有的结点都要操作,丢。
void solve(){
int n;
cin >> n;
vector<vector<int>> al(n + 1);
vector<long long> weights(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> weights[i];
}
for (int i = 2; i <= n; ++i) {
int p;
cin >> p;
al[p].push_back(i);
}
auto dfs = [&](auto&& self, int u)->long long {
long long x = INF_LL;
for (const auto& v : al[u]) {
x = min(self(self, v), x);
}
if (x!= INF_LL) {
if (u == 1) {
weights[u] += x;
}
else if (x > weights[u]) {
weights[u] = (weights[u] + x) / 2;
}
else {
weights[u] = x;
}
}
return weights[u];
};
cout << (dfs(dfs, 1)) << '\n';
}
有模板写程序就是好用
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现