Codeforces Round 958 (Div. 2)
1.Codeforces Round 958 (Div. 2)
2.Codeforces Round 957 (Div. 3)3.Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)4.Codeforces Round 960 (Div. 2)5.AtCoder Beginner Contest 3636.Codeforces Round 961 (Div. 2)7.AtCoder Beginner Contest 3628.Codeforces Round 962 (Div. 3)9.Pinely Round 4 (Div. 1 + Div. 2)10.Educational Codeforces Round 168 (Rated for Div. 2)11.AtCoder Beginner Contest 36712.Codeforces Round 967 (Div. 2)13.Codeforces Round 968 (Div. 2)14.Educational Codeforces Round 173 (Rated for Div. 2)15.Educational Codeforces Round 172 (Rated for Div. 2)(C-D)16.Codeforces Round 998 (Div. 3)17.2025牛客寒假算法基础集训营218.2025牛客寒假算法基础集训营1题目链接:Codeforces Round 958 (Div. 2)
总结:C因为常数没转
A. Split the Multiset
fag:模拟
Description:给定一个
Solution:因为最后要得到全
void solve(){ cin >> n >> k; k --; if (n == 1){ cout << 0 << endl; return; } n --; cout << (n + k - 1) / k << endl; }
B. Make Majority
fag: 思维
Description: 给定一个只含
问能否将其变为
Solution:手摸几组样例发现:我们可以把所有连续的多个
- 那么统计连续
的区间个数 , 的个数 。 - 当
时,有解,否则无解。
void solve(){ cin >> n; cin >> s; int x = 0, y = 0; for (int i = 0; i < n; i ++){ if (s[i] == '0') x ++; else y ++; } int xx = 0; bool flag = true; for (int i = 0; i < n; i ++){ if (s[i] == '0' && flag){ xx ++; flag = false; continue; } if (s[i] == '1') flag = true; } if (y >= xx + 1){ cout << "Yes\n"; } else{ cout << "No\n"; } }
C. Increasing Sequence with Fixed OR
fag:位运算
Description:给定一个
Solution:显然我们需要将
然后考虑如何构造。我们只需要依次去掉低位
void solve(){ cin >> n; vector<int> ans; ans.eb(n); for (int i = 0; i < 64; i ++){ if (n >> i & 1){ // 这一位是1 ans.eb(n ^ (1LL << i)); // 注意这里 } } if (ans[ans.size() - 1] == 0) // 注意特判 ans.pop_back(); cout << ans.size() << endl; sort(ans.begin(), ans.end()); for (int i = 0; i < ans.size(); i ++){ cout << ans[i] << " "; } cout << endl; }
D. The Omnipotent Monster Killer
fag:树形DP
Description:一颗有
1 <= n <= 3e5 1 <= ai <= 1e12
Solution:只需要最多
-
如果一个节点在第
个回合删除,那么它的伤害为 -
令
表示, 节点在第 个回合删除,以 为根的子树的伤害最小值。 -
答案
:
void solve(){ cin >> n; vector<int> a(n); vector g(n, vector<int>()); vector f(n, vector<int>(21, 0)); for (int i = 0; i < n; i ++) cin >> a[i]; for (int i = 0; i < n - 1; i ++){ int a, b; cin >> a >> b; a --, b --; g[a].eb(b), g[b].eb(a); } auto dfs = [&](auto self, int u, int v) -> void { for (int i = 1; i <= 20; i ++){ f[u][i] = i * a[u]; } for (auto x : g[u]){ if (x == v) continue; self(self, x, u); for (int i = 1; i <= 20; i ++){ int mi = 1e18; for (int j = 1; j <= 20; j ++){ if (i == j) continue; mi = min(mi, f[x][j]); } f[u][i] += mi; } } }; dfs(dfs, 0, -1); int ans = 1e18; for (int i = 1; i <= 20; i ++){ ans = min(ans, f[0][i]); } cout << ans << endl; }
合集:
题解
标签:
Codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!