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

天梯赛L2题解(017-020)

L2-017 人以群分

偶数对半分最好,奇数的话外向多一个差就更大

#include <bits/stdc++.h>
using namespace std;
#define int long long
using PII = pair<int, int>;void ylh_() {int n;cin >> n;vector<int> a(n + 1);for (int i = 1; i <= n; ++i) {cin >> a[i];}sort(a.begin() + 1, a.end());vector<int> pre(n + 1);for (int i = 1; i <= n; ++i) {pre[i] = pre[i - 1] + a[i];}int diff = pre[n] - 2 * pre[n / 2];cout << "Outgoing #: " << n / 2 + (n % 2 == 1) << '\n';cout << "Introverted #: " << n / 2 << '\n';cout << "Diff = " << diff;
}int32_t main() {ios::sync_with_stdio(0);cin.tie(0);int T = 1;// cin >> T;while (T--) {ylh_();}
}

L2-018 多项式A除以B

比赛的时候拿不到满分就放弃吧,我已调试到疾苦
想拿满分还是不要看我的这题的一坨解QWQ

#include <bits/stdc++.h>
using namespace std;
#define int long longconst double eps = 1e-6;void ylh_() {int n1;cin >> n1;vector<int> a1;vector<double> a2;for (int i = 1; i <= n1; ++i) {int x;double y;cin >> x >> y;a1.push_back(x);a2.push_back(y);}int n2;cin >> n2;vector<int> b1;vector<double> b2;for (int i = 1; i <= n2; ++i) {int x;double y;cin >> x >> y;b1.push_back(x);b2.push_back(y);}if (n1 == 0) {cout << "0 0 0.0\n 0 0 0.0";return;}// 被除式数组,下标为指数vector<double> a3(10010, 0.0);int max_a = 0;for (int i = 0; i < a1.size(); ++i) {a3[a1[i]] = a2[i];if (a1[i] > max_a) max_a = a1[i];}// 除式数组vector<double> b3(10010, 0.0);int max_b = 0;for (int i = 0; i < b1.size(); ++i) {b3[b1[i]] = b2[i];if (b1[i] > max_b) max_b = b1[i];}// 商数组vector<double> c3(10010, 0.0);int max_c = max_a - max_b;while (max_a >= max_b) {if (abs(a3[max_a]) < eps) {max_a--;continue;}double q = a3[max_a] / b3[max_b];c3[max_a - max_b] = q;// 更新被除式for (int i = max_a, j = max_b; i >= 0 && j >= 0; i--, j--) {a3[i] -= b3[j] * q;}while (max_a >= 0 && abs(a3[max_a]) < eps) {max_a--;}}auto print = [&](vector<double>& arr, int max_exp) {int cnt = 0;for (int i = 0; i <= max_exp; ++i) {if (abs(arr[i]) + 0.05 >= 0.1) cnt++;}cout << cnt;if (cnt == 0) {cout << " 0 0.0";} else {for (int i = max_exp; i >= 0; --i) {if (abs(arr[i]) + 0.05 >= 0.1) {cout << ' ' << i << fixed << setprecision(1) << ' ' << arr[i];}}}};print(c3, max_c);cout << '\n';print(a3, max_a);
}int32_t main() {ios::sync_with_stdio(0);cin.tie(0);int T = 1;// cin >> T;while (T--) {ylh_();}return 0;
}

L2-019 悄悄关注

#include <bits/stdc++.h>
using namespace std;
#define int long long
using PSI = pair<string, int>;void ylh_() {int n;cin >> n;set<string> st;for (int i = 1; i <= n; ++i) {string s;cin >> s;st.insert(s);}int m;cin >> m;vector<PSI> a(m + 1);int sum = 0;for (int i = 1; i <= m; ++i) {cin >> a[i].first >> a[i].second;sum += a[i].second;}sort(a.begin() + 1, a.end(), [&](PSI x, PSI y) {return x.first < y.first;});vector<string> ans;for (int i = 1; i <= m; ++i) {if (a[i].second * m > sum) {if (!st.count(a[i].first)) {ans.push_back(a[i].first);}}}for (int i = 0; i < ans.size(); ++i) {cout << ans[i];if (i != ans.size() - 1) {cout << '\n';} else {return;}}cout << "Bing Mei You";
}int32_t main() {ios::sync_with_stdio(0);cin.tie(0);int T = 1;// cin >> T;while (T--) {ylh_();}
}

L2-020 功夫传人

#include <bits/stdc++.h>
using namespace std;
#define int long longvoid ylh_() {int n;double z, r;cin >> n >> z >> r;r /= 100;vector<vector<int>> g(n);vector<int> ddz(n + 1); // 得道者的倍数for (int i = 0; i < n; ++i) {int m;cin >> m;if (m == 0) {int k;cin >> k;ddz[i] = k;}for (int j = 1; j <= m; ++j) {int k;cin >> k;g[i].push_back(k);}}double ans = 0;auto dfs = [&](auto&& dfs, double cur, int u) {// cout << u << ' ' << cur << endl;if (ddz[u] > 0) {ans += cur * ddz[u];return;}double ncur = cur * (1.0 - r);for (auto v : g[u]) {dfs(dfs, ncur, v);}};dfs(dfs, z, 0);int ans_int = ans;cout << ans_int;
}int32_t main() {ios::sync_with_stdio(0);cin.tie(0);int T = 1;// cin >> T;while (T--) {ylh_();}
}
http://www.jsqmd.com/news/518967/

相关文章:

  • 2026年GEO优化服务商深度测评:从技术底层到效果落地的选型分析 - 小白条111
  • Windows本地部署OpenClaw:10分钟搞定飞书AI助手,值不值?
  • 2026年降AI工具哪款支持表格和公式?理工科同学实测这3款
  • 2026年招商加盟GEO优化服务商怎么选?行业深度分析与实测测评 - 小白条111
  • SVN cleanup报错别慌!5分钟搞定wc.db数据库锁定的终极方案
  • 计算机毕业设计java基于微信小程序点餐系统的设计与实现 基于微信小程序的线上餐饮订购平台设计与实现 微信小程序驱动的移动端餐厅点餐与支付系统研发
  • 渐得如意智能自动化办公平台——定义属于你的咒语 - Magic
  • OpenStack物理机与虚拟机外部网络连接:网卡配置实战指南
  • ROS Melodic下移动小车SLAM建图实战:从Ubuntu 18.04环境配置到Gazebo仿真(避坑指南)
  • 探索傅里叶变换与短时傅里叶分析:从理论到脚本实践
  • 从Function Calling到MCP:AI工具化到底解决了什么,没解决什么
  • 第 5 篇:让 Claude 少犯错,验证机制、测试策略与发布检查清单
  • 普源DHO4000示波器数学运算全指南:FFT/积分/微分功能详解
  • COMSOL锂电池模型:风冷、水冷、空冷相变冷却及热电耦合仿真代
  • 域控制器开发避坑实录:从硬件设计到软件集成的5个关键挑战
  • 【NISP】证书全攻略:从入门到进阶的职业路径解析
  • 情绪问题是什么?主要有哪几种表现形式?
  • 基于Matlab的FFT滤波:谐波分析、频段清除与数据提取
  • 电商平台大数据建模:用户行为分析与推荐系统设计
  • 高阶滑模观测器在永磁同步电机无位置算法中的应用:性能卓越,无需低通滤波与相位补偿
  • Debian 13 KDE桌面美化全攻略:从Nordic主题到Papirus图标一步到位
  • 从原理到实践:手把手教你解决模拟版图中的天线效应问题
  • Hive数据一致性问题:分桶表_分区表数据倾斜与一致性保障技巧
  • 自动泊车系统中平行泊车与圆弧直线圆弧可行驶区域分析
  • 学习困难与儿童注意力缺陷的表现及其诊断标准是什么?
  • 为什么你的多线程程序总崩溃?可能是没用好pthread_setname_np这个隐藏功能
  • SDH网络中的POS接口配置实战——从理论到路由器部署
  • 基因编辑技术的伦理争议与投资风险
  • 出自动泊车MPC模型预测控制的路径跟踪(纯代码+运动学): 含误差图、前轮转角图、航向角图及动画展示
  • VirtualBox快速部署Debian12:从零开始的详细指南