SMU 2024 spring 天梯赛自主训练3
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的更多相关文章
- 2018天梯赛第一次训练题解和ac代码
随着评讲的进行代码和题解会逐步放上来 2018天梯赛第一次训练 1001 : 进制转换 Time Limit(Common/Java):1000MS/10000MS Memory Limit: ...
- PTA天梯赛训练题L1-064:估值一亿的AI核心代码(字符串模拟)
Update:smz说regex秒过Orz,yzd记在这里了. 听说今年天梯赛有个烦人的模拟,我便被队友逼着试做一下……一发15,二发20.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...
- 【CCCC天梯赛决赛】
cccc的天梯赛决赛,水题一样的水,中档题以上的还是没做出来.补了一下题,觉得其实也不是很难,主要是练的少. L2-1:红色预警 并查集 我做的时候想不到并查集,想到了也不一定做的出来,都是其实不难. ...
- 记第一届 CCCC-团体程序设计天梯赛决赛 参赛
其他都没什么,上午报道,下午比赛两个半小时,最后139分 但四我超遗憾的是,最后在做L3-1二叉搜索树,因为看到有辣么多人做出来,可是我没做出来啊 比赛结束后看了看其他两道当场吐血,L3-3直捣黄龙不 ...
- L1-049 天梯赛座位分配
L1-049 天梯赛座位分配 (20 分) 天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i ...
- 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code #include <cstdio> #include ...
- 第四届CCCC团体程序设计天梯赛 后记
一不小心又翻车了,第二次痛失200分 1.开局7分钟A了L2-3,一看榜已经有七个大兄弟排在前面了,翻车 * 1 2.把L1-3 A了18分,留了两分准备抢顽强拼搏奖,最后五秒钟把题过了,万万没想到还 ...
- 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard
山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...
随机推荐
- UniRx-unirx中的对象池
UniRx-unirx中的对象池 对象池Unirxunity 对象池 一.对象池模式 <游戏设计模式-对象池模式> 1.概念 定义一个池对象,其包含了一组可重用对象. 其中每个可重用对象都 ...
- 从0到1:CTFer成长之路网上平台的使用以及docker环境配置
1.首先安装docker(这里在kali里演示) sudo su #以root身份运行 apt install docker.io #安装docker systemctl start docker # ...
- macOS Big Sur 11.0.1光盘镜像文件制作
https://blog.csdn.net/hymnal/article/details/110393501
- Linux 内核:设备树(1)dtb格式
Linux 内核:设备树(1)dtb格式 背景 dtb作为二进制文件被加载到内存中,然后由内核读取并进行解析,如果对dtb文件的格式不了解,那么在看设备树解析相关的内核代码时将会寸步难行,而阅读源代码 ...
- 在Linux应用层使用POSIX定时器
在Linux应用层使用POSIX定时器 ref : http://blog.chinaunix.net/uid-28458801-id-5035347.html http://blog.sina.co ...
- Taro 滚动切换tab页
import React, { Component } from 'react' import { View, Text, ScrollView } from '@tarojs/components' ...
- k8s实战 ---- pod 基础
如果你对k8s还不了解,可以看下前文 k8s 实战 1 ---- 初识 (https://www.cnblogs.com/jilodream/p/18245222) 什么是pod,pod在 ...
- python3 中的装饰器总结
前言 python3 中有很多好用的装饰器,本编文章作为个人笔记使用,随时更新. 正文 1. @dataclass 内容来源:chatgpt3.5 @dataclass是一个装饰器,用于给类提供自动生 ...
- 在Django中查找重复项目
在Django中查找重复项目通常涉及使用查询集(QuerySet)和模型(Model).假设你有一个模型,比如Item,你想查找其中重复的项目,可以通过以下步骤来实现: 确定重复的标准: 首先需要确定 ...
- Vue this.$refs的使用
ref 写在标签上时:this.$refs.名字 获取的是标签对应的dom元素 ref 写在组件上时:这时候获取到的是子组件的引用