SMU 2024 spring 天梯赛自主训练3

7-1 2018我们要赢 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

2018
wo3 men2 yao4 ying2 !

7-2 打折 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n,r;
cin >> n >> r;
printf("%.2lf\n", n * (r) * 0.1); return 0;
}

7-3 电子汪 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int a,b;
cin >> a >> b;
for(int i = 0;i < a+ b;i ++)
cout << "Wang!"; return 0;
}

7-4 谁是赢家 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int pa, pb,a=0,b=0;
cin >> pa >> pb;
for(int i = 0;i < 3;i ++){
int x;
cin >> x;
a += (x == 0);
b += (x == 1);
} if(a + pa > b + pb && b != 3) {
printf("The winner is a: %d + %d\n",pa,a);
}else{
printf("The winner is b: %d + %d\n",pb,b);
} return 0;
}

7-5 福到了 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); char c;
int n;
cin >> c >> n;
vector<string> s(n), ans(n);
getline(cin, s[0]);
for (int i = 0; i < n; i ++) {
getline(cin , s[i]);
ans[i] = s[i];
reverse(ans[i].begin(), ans[i].end());
} reverse(ans.begin(), ans.end());
if (ans == s) {
cout << "bu yong dao le\n";
}
for (auto str : ans) {
for (auto i : str)
if (i != ' ') cout << c;
else cout << ' ';
cout << '\n';
} return 0;
}

7-6 倒数第N个字符串 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int L, n;
cin >> L >> n; string s = string(L, 'z');
for (int i = 1; i < n; i ++) {
int cnt = L - 1;
s[cnt]--;
while (s[cnt] < 'a' && cnt >= 0) {
s[cnt] = 'z';
s[--cnt] --;
}
} cout << s << '\n'; return 0;
}

7-7 天梯赛座位分配 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n, sum = 0, m;
cin >> n, m = n;
vector<int> a(n + 1), now(n + 1);
for (int i = 1; i <= n; i ++) {
cin >> a[i];
a[i] *= 10;
sum += a[i];
} vector ans(n + 1, vector<int>());
int people = 0, val = 1;
while (sum--) {
for (int i = 1; i <= n; i ++) {
if (ans[i].size() < a[i]) {
ans[i].push_back(val);
if (people + 1 == n) val += 2;
else val ++;
people = 0;
for (int j = 1; j <= n; j ++)
if (ans[j].size() >= a[j])
people ++;
}
}
} for (int i = 1; i <= n; i ++) {
cout << '#' << i << '\n';
int cnt = 1;
for (int j = 0; j < ans[i].size(); j ++) {
cout << ans[i][j] << " \n"[cnt % 10 == 0];
cnt ++;
}
} return 0;
}

7-8 7206 猜数字 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

直接从\(1000 \sim 9999\)枚举符合n个要求的数,如果只有一个说明答案唯一,否则就不能确定;

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n; auto check = [](int x, array<int, 3> Case) {
vector<int> NumX(5), NumC(5);
for (int i = 4; i >= 1; i --) {
NumX[i] = x % 10, x /= 10;
NumC[i] = Case[0] % 10, Case[0] /= 10;
} int SameNum = 0, SameLoc = 0;
for (int i = 1; i <= 4; i ++)
if (NumC[i] == NumX[i]) SameLoc ++;
for (int i = 1; i <= 4; i ++)
for (int j = 1; j <= 4; j ++)
if (NumC[j] == NumX[i]) {
SameNum ++, NumC[j] = -1;
break;
}
return (SameLoc == Case[2] && SameNum == Case[1]);
}; while (cin >> n) {
if (!n) break;
vector<array<int, 3>> Case(n);
for (auto &[a, b, c] : Case)
cin >> a >> b >> c;
int Ke = 0, ans = 0;
for (int i = 1000; i < 10000; i ++) {
int m = 0;
for (auto v : Case)
if (check(i, v)) m ++;
if (m == n) Ke ++, ans = i;
} if (Ke == 1) cout << ans << '\n';
else cout << "Not sure\n";
} return 0;
}

7-9 分而治之 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

并查集;

考虑将攻打的城市除去外其余点是否都不能连通;

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; struct UFS {
int n;
vector<int> fa; UFS(int n): n(n) {
fa.resize(n + 1);
for (int i = 0; i <= n; i ++)
fa[i] = i;
} int find(int x) {
return fa[x] == x ? x : find(fa[x]);
} void unin(int x, int y) {
x = find(x), y = find(y);
if (x != y) {
fa[x] = y;
}
}
}; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n, m;
cin >> n >> m;
vector<PII> edge(m + 1);
for (int i = 1; i <= m; i ++) {
int u, v;
cin >> u >> v;
edge[i] = {u, v};
} int k;
cin >> k;
while (k --) {
int ke ;
cin >> ke;
set<int> cuit;
for (int i = 0; i < ke; i ++) {
int x;
cin >> x;
cuit.insert(x);
} UFS ufs(n);
for (auto [u, v] : edge) {
if (cuit.count(u) || cuit.count(v)) continue;
ufs.unin(u, v);
} int num = 0;
for (int i = 1; i <= n; i ++) {
if (ufs.find(i) == i) num ++;
} if (num == n) cout << "YES\n";
else cout << "NO\n";
} return 0;
}

7-10 小字辈 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

dfs找到最大辈分并更新每个人的辈分;

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n;
cin >> n;
vector<int> fa(n + 1), Bei(n + 1);
int root = 0, mx = 0;
vector g(n + 1, vector<int>());
for (int i = 1; i <= n; i ++) {
cin >> fa[i];
if (fa[i] == -1) root = i;
else {
g[fa[i]].push_back(i);
}
} auto dfs = [&](auto dfs, int x) -> void{
Bei[x] ++;
for (auto v : g[x]) {
Bei[v] += Bei[x];
dfs(dfs, v);
}
}; dfs(dfs, root); for (int i = 1; i <= n; i ++)
mx = max(mx, Bei[i]); cout << mx << '\n'; vector<int> ans;
for (int i = 1; i <= n; i ++)
if (Bei[i] == mx)
ans.push_back(i); for (auto i : ans)
cout << i << " \n"[i == ans.back()]; return 0;
}

7-11 名人堂与代金券 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

模拟;

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n,g,k;
cin >> n >> g >> k;
vector<pair<string,int>> s(n); int sum = 0;
for(auto &[x,y] : s){
cin >> x >> y;
if(y >= g) sum += 50;
else if(y >= 60) sum += 20;
} sort(s.begin(),s.end(),[](pair<string,int> a,pair<string,int> b){
if(a.second != b.second) return a.second > b.second;
return a.first < b.first;
}); cout << sum << '\n'; int now = 1;
for(int i = 0;i < n;i ++){
int cnt = 1;
cout << now << ' ' << s[i].first << ' ' << s[i].second << '\n';
while(i + 1 < n && s[i].second == s[i + 1].second){
i ++;
cnt ++;
cout << now << ' ' << s[i].first << ' ' << s[i].second << '\n';
}
now += cnt;
if(now > k) break;
} return 0;
}

7-12 秀恩爱分得快 - SMU 2024 spring 天梯赛自主训练3 (pintia.cn)

这题我真的很想吐槽下;

wa了30多发,感觉很ex啊,有0和-0这玩意,而且还有可能两者就没出现在照片里过,还有些函数像是abs,stoi啊,能用一次就用一次,不要多次调用,本来\(\mathcal{O}(mk^2)\)的复杂度也很难过吧,没过那就要要注意一下上面的点,还是冲过去了,400多ms,还有就是可以用vector去记录照片里的人,还有还有,就是最后找出来的ma和mb不能直接比较等于,要和他们各自对对方的亲密度比较,就因为这个玩意一直在测试点5wa,真的服了;

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int n, m;
cin >> n >> m;
vector val(n, vector<double>(n, 0));
vector<int> fu(n, 1); for (int i = 0; i < m; i ++) {
int k;
cin >> k;
vector<int> people(k);
for (int j = 0; j < k; j ++) {
string s;
cin >> s;
int x = stoi(s);
if (s[0] == '-') x = -x, fu[x] = -1;
people[j] = x;
}
double ok = 1.0 / k;
for (int l = 0; l < k; l ++) {
for (int r = l + 1; r < k; r ++) {
int j = people[l], p = people[r];
if (fu[j] != fu[p]) {
val[j][p] += ok;
val[p][j] += ok;
}
}
}
} int a, b;
string x, y;
cin >> x >> y;
a = stoi(x), b = stoi(y);
if (x[0] == '-') a = -a, fu[a] = -1;
if (y[0] == '-') b = -b, fu[b] = -1;
double ma = 0, mb = 0;
for (int i = 0; i < n; i ++) {
if (fu[i] != fu[a])
ma = max(ma, val[a][i]);
if (fu[i] != fu[b])
mb = max(mb, val[b][i]);
} auto print = [&](int x, int y) {
if (fu[x] == -1) cout << '-';
cout << x << ' ';
if (fu[y] == -1) cout << '-';
cout << y << '\n';
}; if (ma == val[a][b] && mb == val[b][a]) {
print(a, b);
} else {
for (int i = 0; i < n; i ++) {
if (val[a][i] == ma && fu[a] != fu[i]) {
print(a, i);
}
}
for (int i = 0; i < n; i ++) {
if (val[b][i] == mb && fu[b] != fu[i]) {
print(b, i);
}
}
} return 0;
}

SMU 2024 spring 天梯赛自主训练3的更多相关文章

  1. 2018天梯赛第一次训练题解和ac代码

    随着评讲的进行代码和题解会逐步放上来 2018天梯赛第一次训练 1001 : 进制转换 Time Limit(Common/Java):1000MS/10000MS     Memory Limit: ...

  2. PTA天梯赛训练题L1-064:估值一亿的AI核心代码(字符串模拟)

    Update:smz说regex秒过Orz,yzd记在这里了. 听说今年天梯赛有个烦人的模拟,我便被队友逼着试做一下……一发15,二发20.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...

  3. 【CCCC天梯赛决赛】

    cccc的天梯赛决赛,水题一样的水,中档题以上的还是没做出来.补了一下题,觉得其实也不是很难,主要是练的少. L2-1:红色预警 并查集 我做的时候想不到并查集,想到了也不一定做的出来,都是其实不难. ...

  4. 记第一届 CCCC-团体程序设计天梯赛决赛 参赛

    其他都没什么,上午报道,下午比赛两个半小时,最后139分 但四我超遗憾的是,最后在做L3-1二叉搜索树,因为看到有辣么多人做出来,可是我没做出来啊 比赛结束后看了看其他两道当场吐血,L3-3直捣黄龙不 ...

  5. L1-049 天梯赛座位分配​​​​​​​

    L1-049 天梯赛座位分配 (20 分) 天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i ...

  6. 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  7. 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  8. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  9. 第四届CCCC团体程序设计天梯赛 后记

    一不小心又翻车了,第二次痛失200分 1.开局7分钟A了L2-3,一看榜已经有七个大兄弟排在前面了,翻车 * 1 2.把L1-3 A了18分,留了两分准备抢顽强拼搏奖,最后五秒钟把题过了,万万没想到还 ...

  10. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

随机推荐

  1. MAC下Cowardly refusing to 'sudo brew install解决方案

    副标题:<论学习英语的重要性> 在执行'sudo brew install cmake'的时候报错,错误信息如下. (一脸懵逼) 解决方案: 其实报错信息都说好了,大概意思是不能用管理员权 ...

  2. js-文件读写和上传下载的简单例子01

    现下,网络越来越快,浏览器的功能和性能越来越好,所以很多时候,已经不需要一些复杂的框架来实现不是非常复杂的功能. 我们只有在以下情况才会考虑使用框架或者现成的第三方组件: 1.功能复杂,自己写没有必要 ...

  3. typroa破解

    Typora 一款 Markdown 编辑器和阅读器 风格极简 / 多种主题 / 支持 macOS,Windows 及 Linux 实时预览 / 图片与文字 / 代码块 / 数学公式 / 图表 目录大 ...

  4. 解决Vue中使用history路由模式出现404的问题

    背景 vue中默认的路由模式是hash,会出现烦人的符号#,如http://127.0.0.1/#/. 改为history模式可以解决这个问题,但是有一个坑是:强刷新.回退等操作会出现404. Vue ...

  5. 12-Python数据库访问

    在CentOS7上安装Mariadb https://blog.csdn.net/NetRookieX/article/details/104734181 常用的增删改查 show databases ...

  6. Git配置环境变量

    由于学习需要装了git,使用终端查看版本号时 提示 'git' 不是内部或外部命令,也不是可运行的程序 或批处理文件. 原因 因为没有配置Git环境变量 解决方法:配置环境变量 开始菜单=>设置 ...

  7. .NET 日志系统-3 结构化日志和集中日志服务

    .NET 日志系统-3 结构化日志和集中日志服务 系列文章 认识.NET 日志系统 https://www.cnblogs.com/ZYPLJ/p/17663487.html .NET 认识日志系统- ...

  8. 高通安卓:自定义QFile烧录镜像

    高通安卓:自定义QFile烧录镜像 背景 在某个项目中,因为USB口的问题,无法使用fastboot进行download. 同事提供了一份用与QFile的rawprogram.xml烧写.觉得这个方法 ...

  9. 学习嵌入式为什么要学习uboot

    ref:http://www.elecfans.com/d/617674.html 为什么要有BootLoader 背景 很多人学习嵌入式一开始就搞Linux,这样子容易对底层缺少了解. 基础介绍 计 ...

  10. 缺氧debu模式

    OxygenNotIncluded_Data(E:\SteamLibrary\steamapps\common\OxygenNotIncluded\OxygenNotIncluded_Data) 文件 ...