SMU 2024 spring 天梯赛自主训练2
SMU 2024 spring 天梯赛自主训练2
7-1 I Love GPLT - SMU 2024 spring 天梯赛自主训练2 (pintia.cn)
PHP
点击查看代码
I
L
o
v
e
G
P
L
T
7-2 是不是太胖了 - SMU 2024 spring 天梯赛自主训练2 (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 h;
cin >> h;
printf("%.1lf",(h-100)*0.9 * 2);
return 0;
}
7-3 大笨钟 - SMU 2024 spring 天梯赛自主训练2 (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 h,m;
char op;
cin >> h >> op >> m;
int now = h * 60 + m;
if(now >= 0 && now <= 12* 60){
printf("Only %02d:%02d. Too early to Dang.",h,m);
}else{
for(int i = 0;i < (now + 59) / 60 - 12 ;i ++)
cout << "Dang";
}
return 0;
}
7-4 到底是不是太胖了 - SMU 2024 spring 天梯赛自主训练2 (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 t;
cin >> t;
while(t -- ){
double h,w;
cin >> h >> w;
double Per = (h-100)*0.9*2;
double Nor = Per * 0.1;
if(fabs(w - Per) < Nor)
cout << "You are wan mei!\n";
else if(w > Per)
cout << "You are tai pang le!\n";
else
cout << "You are tai shou le!\n";
}
return 0;
}
7-5 情人节 - SMU 2024 spring 天梯赛自主训练2 (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);
vector<string> s;
string str;
cin >> str;
while(str != "."){
s.push_back(str);
cin >> str;
}
if(s.size() < 2){
cout << "Momo... No one is for you ...\n";
}else if(s.size() < 14)
cout << s[1] << " is the only one for you...\n";
else cout<< s[1] << " and " << s[13] << " are inviting you to dinner...";
return 0;
}
7-6 外星人的一天 - SMU 2024 spring 天梯赛自主训练2 (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 t;
cin >> t;
while(t --){
int d,h,m,now;
char c;
cin >> d >> h >> c >> m;
now = h * 60 + m;
if(!d)
printf("%d %02d:%02d\n",d,h,m);
else {
if(d % 2 == 0) now += 24*60;
printf("%d %02d:%02d\n",(d+1)/2,now / 60 / 2,(now/2)%60);
}
}
return 0;
}
7-7 宇宙无敌加法器 - SMU 2024 spring 天梯赛自主训练2 (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);
string JIn;
string NumA, NumB;
cin >> JIn >> NumA >> NumB;
vector<int> wei(30);
reverse(JIn.begin(),JIn.end());
reverse(NumA.begin(),NumA.end());
reverse(NumB.begin(),NumB.end());
string zero = "000000000000000000000";
JIn += zero,NumA += zero, NumB += zero;
vector<int> w(30);
string ans = "000000000000000000000";
for(int i = 0;i <= 20;i ++){
int l = JIn[i] - '0';
if(!l) l = 10;
int num = (NumA[i] - '0') + (NumB[i] - '0') + w[i];
w[i+1] += num / l;
ans[i] = char('0' + num % l);
}
reverse(ans.begin(),ans.end());
for(int i = 0;i < ans.size();i ++){
if(ans[i] != '0'){
cout << ans.substr(i) << '\n';
return 0;
}
}
cout << 0 << '\n';
return 0;
}
7-8 古风排版 - SMU 2024 spring 天梯赛自主训练2 (pintia.cn)
先补充到n的整数倍,然后倒序每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;
cin >> n;
string s;
getline(cin,s);
getline(cin,s);
int m = s.size();
if(m % n){
for(int i = 0;i < n - m % n;i ++)
s += ' ';
m = s.size();
}
int dex = n;
reverse(s.begin(),s.end());
for(int i = 0;i < n;i ++){
dex --;
for(int j=dex;j < m;j += n)
cout << s[j];
cout << '\n';
}
return 0;
}
7-9 抢红包 - SMU 2024 spring 天梯赛自主训练2 (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 people{
int id,num = 0;
double val = 0;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<people> Ke(n + 1);
for(int i = 1;i <= n;i ++){
int k,num = 0;
cin >> k;
Ke[i].id = i;
for(int j = 0;j < k;j ++){
int ni,pi;
cin >> ni >> pi;
num += pi;
Ke[ni].num ++;
Ke[ni].val += pi;
}
Ke[i].val -= num;
}
Ke.erase(Ke.begin());
sort(Ke.begin(),Ke.end(),[&](people a,people b){
if(a.val == b.val && a.num == b.num) return a.id < b.id;
if(a.val == b.val) return a.num > b.num;
return a.val > b.val;
});
for(auto [id,num,val] : Ke){
printf("%d %.2lf\n",id, val / 100);
}
return 0;
}
7-10 家庭房产 - SMU 2024 spring 天梯赛自主训练2 (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 people {
int id = -1, num, fang, s;
double avgs, avgfang;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> fa(10010);
iota(fa.begin(), fa.end(), 0);
auto find = [&](auto self, int x)-> int{
return fa[x] == x ? x : fa[x] = self(self, fa[x]);
};
bitset<10010> vis;
vector<people> info(10010);
for (int i = 0; i < n; i ++) {
int id, x, y, k, f, s;
cin >> id >> x >> y >> k;
int u = find(find, id);
vis[id] = 1;
if (x != -1) {
x = find(find, x);
vis[x] = 1;
fa[x] = u;
}
if (y != -1) {
y = find(find, y);
vis[y] = 1;
fa[y] = u;
}
for (int j = 0; j < k; j ++) {
int z;
cin >> z;
vis[z] = 1;
z = find(find, z);
fa[z] = u;
}
cin >> f >> s;
info[id] = {id, 1, f, s, 0, 0};
}
vector<people> res(10010), ans;
set<int> exit;
for (int i = 0; i < 10000; i ++) {
if (vis[i]) {
int u = find(find, i);
if (res[u].id == -1) res[u].id = i;
res[u].num ++;
res[u].fang += info[i].fang;
res[u].s += info[i].s;
exit.insert(u);
}
}
for (auto v : exit) {
ans.push_back(res[v]);
}
for (auto &i : ans) {
i.avgs = i.s * 1.0 / i.num;
i.avgfang = i.fang * 1.0 / i.num;
}
sort(ans.begin(), ans.end(), [&](people a, people b) {
if (a.avgs != b.avgs) return a.avgs > b.avgs;
return a.id < b.id;
});
printf("%d\n", ans.size());
for (auto i : ans) {
printf("%04d %d %.3lf %.3lf\n", i.id, i.num, i.avgfang, i.avgs);
}
return 0;
}
7-11 功夫传人 - SMU 2024 spring 天梯赛自主训练2 (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;
double r;
cin >> n;
vector<double> z(n + 1);
vector<int> DeDao(n + 1);
cin >> z[0] >> r;
vector g(n + 1, vector<int>());
for (int i = 0; i < n; i ++) {
int k, x;
cin >> k;
if (!k) cin >> x, DeDao[i] = x;
else {
for (int j = 0; j < k; j ++) {
cin >> x;
g[i].push_back(x);
}
}
}
double ans = 0;
auto dfs = [&](auto self, int now) {
if (DeDao[now]) {
ans += z[now] * DeDao[now];
return;
}
for (auto v : g[now]) {
z[v] = z[now] * (100 - r) * 0.01;
self(self, v);
}
};
dfs(dfs, 0);
cout << (int) ans << '\n';
return 0;
}
7-12 链表去重 - SMU 2024 spring 天梯赛自主训练2 (pintia.cn)
开1e6的数组用对应地址记录结点信息以及下一个地址,按初始地址构建两条链,碰到重复的就丢到另一条链;
#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 st, n;
cin >> st >> n;
vector<PII> L1(n), L2(n);
vector<PII> Num(100100);
for (int i = 0; i < n; i ++) {
int x, a, addr;
cin >> addr >> a >> x;
Num[addr] = {a, x};
}
int cnt1 = 0, cnt2 = 0;
set<int> vis;
while (st != -1) {
if (vis.count(abs(Num[st].first))) {
L2[cnt2 ++] = {Num[st].first, st};
} else {
vis.insert(abs(Num[st].first));
L1[cnt1 ++] = {Num[st].first, st};
}
st = Num[st].second;
}
auto print = [](int cnt, vector<PII> &L) -> void{
for (int i = 0; i < cnt; i ++) {
printf("%05lld %lld ", L[i].second, L[i].first);
if (i == cnt - 1) printf("-1\n");
else printf("%05lld\n", L[i + 1].second);
}
};
print(cnt1, L1);
print(cnt2, L2);
return 0;
}