当前位置: 首页 > news >正文

CSP-S 22

9.16

原来史可以连着吃

挂了100

t1

简单贪心,不多解释。

没有大样例爆了

code

点击查看代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e18;
int minn;
int T;
int cnt2, cnt3, cnt4;signed main()
{ios::sync_with_stdio(0);cin.tie(0);cin >> T;while (T--){cin >> cnt2 >> cnt3 >> cnt4;int ans = 0;if (cnt3 == cnt4 && cnt3 == 0){cout << cnt2 / 5 << "\n";continue;}if (cnt3 / 2 >= cnt4) // 3 3 4{ans += cnt4;cnt3 -= 2 * cnt4;if (cnt3 >= cnt2) // 2 2 3 3ans += cnt2 / 2;else{ans += cnt3 / 2;cnt2 -= cnt3 / 2 * 2;//注意 /2 后再*2 ,只有满2才减ans += cnt2 / 5; // 2 2 2 2 2}}else // 剩2,4{ans += cnt3 / 2;cnt4 -= cnt3 / 2;if (cnt2 > cnt4 / 2) // 2 4 4{ans += cnt4 / 2;cnt2 -= cnt4 / 2;if (cnt4 % 2 == 1)if (cnt2 >= 3)++ans, cnt2 -= 3;ans += cnt2 / 5;}elseans += cnt2;}cout << ans << "\n";}return 0;
}

t2

考虑分成链与点dp ,详见代码

code

点击查看代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 10;
const int mod = 998244353;
int n, ans;
int a[N], dp[N];inline int km(int a, int b)
{int ans = 1;while (b){if (b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cin >> n;for (int i = 1; i <= n; ++i)//将边看作有向cin >> a[i];sort(a + 1, a + 1 + n); // 排序并不影响结果,有序更好算dp[0] = 1;for (int i = 1; i <= n; ++i){for (int j = a[i - 1] + 1; j <= a[i]; ++j) for (int k = j; k; --k)dp[k] = (dp[k] + dp[k - 1]) % mod; // 倒序避免更新重 dp[i][j]=dp[i-1][j]+dp[i-1][j-1]ans = (ans + dp[1]) % mod;ans = (ans - a[i]) % mod;for (int j = 1; j <= a[i]; ++j)dp[j - 1] = (dp[j - 1] + (j - 1) * j % mod * dp[j] % mod) % mod;}cout << ans * km(2, mod - 2) % mod << "\n";//正向与反向,/2return 0;
}

t3

不是哥们,wyx \(O(n^2log_n)\) 过了,我的就 T ??? (虽然正解 \(O(nlog_n)\)

正解为树型dp状物。

code

点击查看代码
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, k;
vector<int> e[N];
int dis[N], cnt, lim;void dfs(int x, int f)
{dis[x] = 1;for (auto y : e[x]){if (y == f)continue;dfs(y, x);dis[x] = min(dis[x], dis[y] + 1);}for (auto y : e[x]){if (y == f)continue;if (dis[x] + dis[y] <= 0)continue;dis[x] = max(dis[x], dis[y] + 1);}if (dis[x] > lim)dis[x] = -lim, ++cnt;
}inline bool check(int up)
{lim = up;cnt = 0;dfs(1, 0);if (dis[1] > 0)++cnt;return cnt <= k;
}inline int fen()
{int l = 1, r = n, ans = r;while(l<=r){int mid = (l + r) >> 1;if(check(mid))r = mid - 1, ans = mid;elsel = mid + 1;}return ans;
}signed main()
{ios::sync_with_stdio(0);cin.tie(0);cin >> n >> k;for (int i = 1, u, v; i < n; ++i){cin >> u >> v;e[u].push_back(v);e[v].push_back(u);}int ans = fen();cout << ans;return 0;
}

t4

咕,太过神秘了。

累了,不想写了,凑合看。

http://www.jsqmd.com/news/17824/

相关文章:

  • /usr/bin/sudo 二进制文件的权限有问题,导致所有用户都无法使用 sudo
  • MySQL 8.0.43社区版本安装流程
  • 读书笔记:深入理解java虚拟机
  • CSP-S 19
  • LangGraph 记忆系统实战:反馈循环 + 动态 Prompt 让 AI 持续学习
  • 【HOWTO】购买和销售二手测试仪器指南
  • CSP-S 18
  • 研1转码自学黑马程序员Python第7天 | Python函数知识 - 指南
  • 小马算力致敬程序员
  • Project. 2025.11化学小组pre
  • 蛋白表达标签:重组蛋白研究的精妙引擎
  • 106.腾讯地图位置服务再出错
  • Luogu P10034 「Cfz Round 3」Circle 题解 [ 蓝 ] [ 背包 DP ] [ 质数筛 ] [ 图论 ] [ 构造 ]
  • 2025.10.20模拟赛
  • 20232410 2025-2026-1 《网络与系统攻防技术》实验二实验报告
  • SQLite简单使用
  • apache服务配置
  • 心理咨询系统
  • Adaptive Learning Rate(自适应学习率) - -一叶知秋
  • 新学期每日总结(第12天)
  • 17 线程的创建
  • 2025.10.20总结 - A
  • 一般公共预算收入 + 全国政府性基金收入
  • 从C10K到Reactor:事件驱动,如何重塑高并发服务器的网络架构
  • AI助力可再生能源系统优化研究
  • 结对项目:小学四则运算题目生成器
  • 数据范围
  • CF2107E Ain and Apple Tree
  • P14262 [ROI 2015 Day1] 自动好友
  • 傻瓜式处理kauditd0病毒程序记录