当前位置: 首页 > 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.gsyq.cn/news/25661.html

相关文章:

  • /usr/bin/sudo 二进制文件的权限有问题,导致所有用户都无法使用 sudo
  • CSP-S 19
  • 研1转码自学黑马程序员Python第7天 | Python函数知识 - 指南
  • 从C10K到Reactor:事件驱动,如何重塑高并发服务器的网络架构
  • 数据范围
  • CF2107E Ain and Apple Tree
  • 2025,为什么公众号编辑器排版决定阅读完成率?——一次从流程到结果的深评
  • P14262 [ROI 2015 Day1] 自动好友
  • win10 升级 win11 后时间更新失败
  • Hands on Deep Learning Chapter 3 线性神经网络
  • 超越技术范畴:低代码如何重塑企业数字文化
  • 详细介绍:1、手把手教你入门设计半桥LLC开关电源设计,LLC谐振腔器件计算
  • 十六天
  • 20251019
  • 【上青了】
  • [VIM] reverse multiple lines in VIM
  • Tuack 生成比赛题目 PDF 笔记
  • 4060显卡也能玩转AI改图!Flux.1 Kontext Dev GGUF版本超详细入门教程 - 实践
  • 提升生产力:8个.NET开源且功能强大的快速开发框架
  • 使用c++14标准实现函数注册包装
  • 【VSCode中Java创建环境安装的三个层级之Maven篇】(Windows版)
  • 2025年不锈钢酸洗钝化液厂家推荐排行榜,环保型不锈钢管酸洗钝化液,不锈钢清洗钝化液,酸洗钝化处理工艺及不锈钢清洗剂公司推荐
  • 2025年法兰保护罩厂家推荐排行榜,阀门保温罩,法兰罩,法兰防溅罩,法兰保护套,专业防护与定制服务优质供应商
  • 百度网盘非会员下载慢怎么解决 - fosgrignonhto
  • d435i 标定 imu和相机 用来复现vins_fusion - 教程
  • K230基础-摄像头的使用 - 详解
  • 2025年市面上高杆灯品牌Top10权威推荐榜单
  • Spring AOP 原理
  • 250921
  • Jvm参数分类