CodeForces Round #544 Div.3
A. Middle of the Contest
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; int h1, m1, h2, m2; int tim1 = 0, tim2 = 0; int main() { scanf("%d:%d", &h1, &m1); scanf("%d:%d", &h2, &m2); tim1 = h1 * 60 + m1; tim2 = h2 * 60 + m2; tim2 -= tim1; tim2 /= 2; tim1 += tim2; int h3 = tim1 / 60, m3 = tim1 % 60; printf("%02d:%02d\n", h3, m3); return 0; }
B. Preparation for International Women's Day
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N, K; int a[maxn], vis[110]; int main() { scanf("%d%d", &N, &K); int ans = 0, cnt = 0; for(int i = 1; i <= N; i ++) { int x; scanf("%d", &x); if(x % K == 0) ans ++; else vis[x % K] ++; } ans /= 2; for(int i = 1; i <= K / 2; i ++) { if(i * 2 != K) ans += min(vis[i], vis[K - i]); else ans += (vis[i] / 2); } printf("%d\n", ans * 2); return 0; }
C. Balanced Team
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int a[maxn]; int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", &a[i]); sort(a, a + N); int maxx = 0; int l = 0, r = 0; while(l <= r && r < N && l < N) { while(a[r] - a[l] <= 5 && r < N) r ++; maxx = max(maxx, r - l); l ++; } printf("%d\n", maxx); return 0; }
D. Zero Quantity Maximization
不敢相信现在会因为数组开小 wa 了四发 2e5 被我开成 1e5 我都不知道我这四次在改什么 是猪吧
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int a[maxn], b[maxn]; map<pair<int, int> , int> mp; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { scanf("%d", &N); for(int i = 0; i < N; i ++) scanf("%d", &a[i]); int cnt = 0, maxx = 0; mp.clear(); for(int i = 0; i < N; i ++) { scanf("%d", &b[i]); if(a[i] == 0) { if(b[i] == 0) cnt ++; continue; } int t = gcd(a[i], b[i]); pair<int, int> p; p.first = a[i] / t, p.second = b[i] / t; if(p.first < 0) p.first *= -1, p.second *= -1; mp[p] ++; maxx = max(maxx, mp[p]); } printf("%d\n", maxx + cnt); return 0; }
E. K Balanced Teams
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 5050; int N, K; int a[maxn], dp[maxn][maxn]; int main() { scanf("%d%d", &N, &K); for(int i = 1; i <= N; i ++) scanf("%d", &a[i]); sort(a + 1, a + N + 1); memset(dp, 0, sizeof(dp)); int pos = 1; for(int i = 1; i <= N; i ++) { while(a[i] - a[pos] > 5 && pos <= N) pos ++; for(int j = 1; j <= min(K, i); j ++) { dp[i][j] = max(dp[i - 1][j], dp[pos - 1][j - 1] + i - pos + 1); } } int ans = 0; for(int i = 1; i <= K; i ++) { ans = max(ans, dp[N][i]); } printf("%d\n", ans); return 0; }
F1. Spanning Tree with Maximum Degree
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N, M; vector<int> v[maxn]; int vis[maxn], son[maxn]; int maxx = 0, temp; vector<int> u; vector<vector<int> > ans; void bfs(int st) { vis[st] = 1; queue<int> q; while(!q.empty()) q.pop(); q.push(st); while(!q.empty()) { int tp = q.front(); q.pop(); for(int i = 0; i < v[tp].size(); i ++) { if(!vis[v[tp][i]]) { vis[v[tp][i]] = 1; printf("%d %d\n", tp, v[tp][i]); q.push(v[tp][i]); } } } } int main() { scanf("%d%d", &N, &M); while(M --) { int a, b; scanf("%d%d", &a, &b); v[a].push_back(b); v[b].push_back(a); son[a] ++, son[b] ++; } for(int i = 1; i <= N; i ++) { if(son[i] > maxx) { maxx = son[i]; temp = i; } } bfs(temp); return 0; }
F2. Spanning Tree with One Fixed Degree
今天也是被奶茶治愈的一天
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!