当前位置:   article > 正文

2023天梯赛个人题解_天梯赛选拔2023第四场答案

天梯赛选拔2023第四场答案


最后只拿了178分,大佬轻喷。

L1-1 最好的文档

#include<bits/stdc++.h>
using namespace std;

void solve(){
	cout << "Good code is its own best documentation.";
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

L1-2 什么是机器学习

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;

void solve(){
	cin >> n >> m;
	cout << n + m - 16 << endl << n + m - 3 << endl << n + m - 1 << endl << n + m;
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

L1-3 程序员买包子

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;

void solve(){
	string s;
	cin >> n >> s >> m >> k;
	if(k == n){
		cout << "mei you mai " << s << " de";
		return ;
	}
	
	if(k == m){
		cout << "kan dao le mai " << s << " de";
		return ; 
	}
	
	cout << "wang le zhao mai " << s << " de";
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

L1-4 进化论

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		int a, b, c;
		cin >> a >> b >> c;
		if(c == a * b){
			cout << "Lv Yan\n";
		}else if(c == a + b){
			cout << "Tu Dou\n";
		}else	cout << "zhe du shi sha ya!\n"; 
	}
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

L1-5 猜帽子游戏

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;
int col[110];

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> col[i];
	cin >> k;
	for(int i = 1; i <= k; i++){
		bool f = 1;
		int cnt = 0;
		for(int j = 1; j <= n; j++){
			int x;	cin >> x;
			if(!x)	cnt++;
			else if(x != col[j])	f = 0;
		}
		if(!f || cnt == n)	cout << "Ai Ya\n";
		else	cout << "Da Jiang!!!\n";
	}
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

L1-6 剪切粘贴

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;

void solve(){
	string s;
	cin >> s >> n;
	s = " " + s;
	for(int i = 1; i <= n; i++){
		int l, r;	string p1, p2;
		cin >> l >> r >> p1 >> p2;
		string t = s.substr(l, r - l + 1);
		s = s.substr(0, l) + s.substr(r + 1);
		int sz = p1.size();
		p1 += p2;
		
		int k = s.find(p1);
		if(k != -1)	s = s.substr(0, k + sz) + t + s.substr(k + sz);
		else	s += t;
	}
	s = s.substr(1);
	cout << s;
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

L1-7 分寝室

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;
int sum1, sum2;
int ans1 = -1, ans2 = -1;

void solve(){
	cin >> sum1 >> sum2 >> n;
	
	vector<int> res1, res2;
	for(int i = 2; i * i <= sum1; i++){
		if(sum1 % i == 0){
			res1.push_back(i);
			res1.push_back(sum1 / i);
		}
	}
	res1.push_back(1);
	
	for(int i = 2; i * i <= sum2; i++){
		if(sum2 % i == 0){
			res2.push_back(i);
			res2.push_back(sum2 / i);
		}
	}
	res2.push_back(1);
	
	for(auto i : res1)
		for(auto j : res2)	if(i + j == n){
			if(ans1 == -1 && ans2 == -1)	ans1 = i, ans2 = j;
			else{
				int d1 = abs((sum1 / ans1) - (sum2 / ans2));
				int d2 = abs((sum1 / i) - (sum2 / j));
				if(d2 < d1)	ans1 = i, ans2 = j;
			}
		}
	
	if(ans1 == -1 && ans2 == -1)	cout << "No Solution";
	else	cout << ans1 << ' ' << ans2;
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45

L1-8 谁管谁叫爹

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		int a, b;	cin >> a >> b;
		bool f = a > b;
		int na = a, nb = b;
		int suma = 0, sumb = 0;
		
		while(a){
			suma += a % 10;
			a /= 10;
		}
		
		while(b){
			sumb += b % 10;
			b /= 10;
		}
		
		bool f1 = (na % sumb == 0);
		bool f2 = (nb % suma == 0);
		
		if(f1 && !f2)	cout << "A\n";
		else if(!f1 && f2)	cout << "B\n";
		else cout << (f ? "A" : "B") << endl;
	}
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

L2-1 堆宝塔

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _;

void solve(){
	cin >> n;
	stack<int> s1, s2;
	
	int cnt = 0;
	int mx = 0;
	for(int i = 1; i <= n; i++){
		int x;	cin >> x;
		
		if(!s1.size() || x < s1.top()){
			s1.push(x);
			continue;
		}
		
		if(!s2.size() || x > s2.top()){
			s2.push(x);
			continue;
		}
		
		cnt++;
		mx = max(mx, (int)s1.size());
		while(s1.size())	s1.pop();
		
		while(s2.size() && s2.top() > x){
			s1.push(s2.top());
			s2.pop();
		}
		s1.push(x);
	}
	if(s1.size())	cnt++, mx = max(mx, (int)s1.size());
	if(s2.size())	cnt++, mx = max(mx, (int)s2.size());
	cout << cnt << ' ' << mx;
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

L2-2 天梯赛的赛场安排

#include<bits/stdc++.h>
using namespace std;

int n, m, k, T, t, _, c;

map<int, string> mp;	//第i个是哪个学校
map<string, int> Res;	//学校需要联系的监考人数

void solve(){
	cin >> n >> c;
	
	set<pair<int, int> > S;	//{剩余座位数,赛场}
	set<pair<int, string> > P;	//{人数,学校}
	int sz = 0;
	int ans = 0;
	
	for(int i = 1; i <= n; i++){
		pair<int, string> res;
		cin >> res.second >> res.first;
		mp[i] = res.second;
		res.first = -res.first;	//升序所以加个-	这样就按照人数从大到小排了
		P.insert(res);
	}
	
	while(P.size()){
		string s = (*P.begin()).second;
		int a = -(*P.begin()).first;
		P.erase(P.begin());
		
		if(a >= c){
			Res[s] += a / c;
			ans += a / c;
			a %= c;
			if(a)	P.insert({-a, s});
			continue;
		}
		
		if(!S.size()){
			ans++;
			S.insert({++sz, c - a});
		}else{
			bool f = 0;
			int k, p;
			for(auto j : S){
				int x = j.second, pos = j.first;
				if(x >= a){
					f = 1;
					k = x;	p = pos;
					break;
				}
			}
			
			if(f){
				S.erase({p, k});
				k -= a;
				if(k > 0)	S.insert({p, k});
			}else{
				ans++;
				S.insert({++sz, c - a});
			}
		}
		Res[s]++;
	}
	
	for(int i = 1; i <= n; i++)
		cout << mp[i] << ' ' << Res[mp[i]] << endl;
	cout << ans;
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

L2-3 锦标赛

#include<bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
#define PII pair<int, int>
#define fi first
#define sc second
#define LL long long
#define vi vector<int>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 2e5 + 5;
const int M = 2e5 + 5;
const int mod = 998244353;
const int Mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const LL inff = 0x3f3f3f3f3f3f3f3f;
int n, m, k, t, T, _;

int ans[1 << 19], a[20][1 << 19], pos[20][1 << 19];

void solve(){
	cin >> k;
	for(int i = 1; i <= k; i++)
		for(int j = 1; j <= 1 << (k - i); j++){
			cin >> a[i][j];
			if(i == 1)	ans[(j << 1) - 1] = a[i][j], pos[i][j] = j << 1;
			else{
				int mx = max(a[i][j], max(a[i - 1][j << 1], a[i - 1][(j << 1) - 1]));
				if(a[i][j] < a[i - 1][j << 1] && a[i][j] < a[i - 1][(j << 1) - 1]){
					cout << "No Solution\n";
					return ;
				}else if(a[i][j] >= a[i - 1][j << 1]){
					ans[pos[i - 1][j << 1]] = a[i][j];
					pos[i][j] = pos[i - 1][(j << 1) - 1];
				}else{
					ans[pos[i - 1][(j << 1) - 1]] = a[i][j];
					pos[i][j] = pos[i - 1][j << 1];
				}
				a[i][j] = mx;
			}
		}
	int mx;	cin >> mx;
	if(a[k][1] <= mx)	ans[pos[k][1]] = mx;
	else{
		cout << "No Solution\n";
		return ;
	}

	for(int i = 1; i <= 1 << k; i++)
		cout << ans[i] << " \n"[i == 1 << k];
}

int main(){
	//for(cin >> _; _--;)
		solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

L2-4 寻宝图

#include<bits/stdc++.h>
using namespace std;
#define PII pair<int, int> 
int n, m, k, T, t, _;
vector<vector<char> > aa;
vector<vector<bool> > vis;
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int cnt, ans;

bool check(int i, int j){
	if(i < 1 || i > n || j < 1 || j > m)	return false;
	if(aa[i][j] == '0' || vis[i][j])	return false;
	return true;
}

void bfs(int i, int j){
	queue<PII> q;
	q.push({i, j});
	vis[i][j] = 1;
	bool f = 0;
	
	while(q.size()){
		int x = q.front().first, y = q.front().second;
		q.pop();
		
		if(aa[x][y] != '1')	f = 1;
		
		for(int i = 0; i < 4; i++){
			int dx = x + dir[i][0], dy = y + dir[i][1];
			if(!check(dx, dy))	continue;
			q.push({dx, dy});
			vis[dx][dy] = 1;
		}
	}
	if(f)	ans ++;
}

void solve(){
	cin >> n >> m;
	vector<vector<char> > a(n + 1, vector<char> (m + 1));
	vector<vector<bool> > v(n + 1, vector<bool> (m + 1));
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	aa = a;
	vis = v;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(!vis[i][j] && aa[i][j] != '0')	bfs(i, j), cnt++;
		
	cout << cnt << ' ' << ans;
}

int main(){
	solve();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/796475
推荐阅读
相关标签
  

闽ICP备14008679号