当前位置:   article > 正文

2023睿抗机器人开发大赛CAIP-编程技能赛-本科组(省赛)

2023睿抗机器人开发大赛CAIP-编程技能赛-本科组(省赛)

在这里插入图片描述

RC-u1 亚运奖牌榜

记录金银铜奖牌数,逐个对比或者结构体都可以

code:

#include<bits/stdc++.h>

using namespace std;

struct node{
	int id;
	int a;
	int b;
	int c;
	bool operator <(const node &fk){
		if(a!= fk.a) return a > fk.a;
		else if(b != fk.b) return b > fk.b;
		else return c > fk.c;
	} 
};

const int N = 1e3 + 7;
node sb[3];
int n;

void solve(){
	cin >> n;
	sb[0].id = 0,sb[1].id = 1;
	for(int i = 0;i < n;i ++){
		int idx; cin >> idx;
		int x; cin >> x;
		if(x == 1) sb[idx].a ++;
		else if(x == 2) sb[idx].b ++;
		else sb[idx].c ++;
	}
	sort(sb,sb + 2);
	if(sb[0].id == 0){
		for(int i = 0;i < 2;i ++){
			cout << sb[i].a << " " << sb[i].b << " " << sb[i].c;
			cout << endl;
		}
	} else{
		for(int i = 1;i >= 0;i --){
			cout << sb[i].a << " " << sb[i].b << " " << sb[i].c;
			cout << endl;
		}		
	}
	if(sb[0].id == 0) cout << "The first win!";
	else cout << "The second win!";
}

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

RC-u2 出院

注意看会不会有多个组成方式,多个的依旧是D

code:

#include<bits/stdc++.h>

using namespace std;

const int N = 1e2 + 7;
int n,m;

void solve(){
	cin >> n >> m;
	map<string,string> mp;
	for(int i = 0;i < n;i ++){
		string s; cin >> s;
		string x; cin >> x;
		mp[s] = x;
	}
	map<string,string> mp2;
	for(int i = 0;i < m;i ++){
		string s; cin >> s;
		if(mp.find(s) != mp.end()){
			cout << mp[s] << endl;
			continue;
		}
		int flag = 0;
		int sum = 0;
		for(int j = 1;j < s.size();j ++){
			string a = s.substr(0,j);
			string b = s.substr(j,s.size() - j);
			if(mp.find(a) != mp.end() && mp.find(b) != mp.end()){
				string c = a + b;
				string d = mp[a];
				d += mp[b];
				mp2[c] = d;
				flag = 1;
				sum ++;
			} 
		}
		if(!flag) cout << "D" << endl; 
		else{
			if(sum > 1) cout << "D" << endl;
			else cout << mp2[s] << 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
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

RC-u4 相对论大师

首先带着 0 1 存一下单向图
然后对每种可能开始的情况跑一下bfs看看最短的路径
比如出现过“fk” bfs看看可不可以从 “fk 1” 到达 “fk 0” 或者 可不可以从 “fk 1” 到达 “fk 0”,这样即可以通过fk 0 = fk 1
bfs中记录路径

code:

#include<bits/stdc++.h>

using namespace std;

const int N = 1e3 + 7;
int n;
map<string,vector<string>> g;
map<string,string> pre;
string ans1 = "-1",ans2 = "-1"; 
map<string,int> d;
int mn = 1e9;

int bfs(string s1,string s2){
	pre.clear();
	d.clear();
	queue<string> q;
	q.push(s1);
	while(q.size()){
		string t = q.front();
		q.pop();
		if(t == s2) return d[t];
		for(auto x : g[t]){
			if(d.find(x) != d.end()) continue;
			pre[x] = t;
			d[x] = d[t] + 1;
			q.push(x);
		}
	}
	return -1;
} 

void solve(){
	cin >> n;
	map<string,int> mp;
	for(int i = 0;i < n;i ++){
		string s1,s2; cin >> s1 >> s2;
		string s3,s4; cin >> s3 >> s4;
		string a = s1 + " " + s2,b = s3 + " " + s4;
		g[a].push_back(b);
		mp[s1] = 1,mp[s3] = 1; 
	} 
	for(auto x : mp){
		string s1 = x.first + " 0";
		string s2 = x.first + " 1";
		int sb = bfs(s1,s2);
		if(sb != -1 && sb < mn){
			mn = sb;
			ans1 = s1,ans2 = s2;
		}
		sb = bfs(s2,s1);
		if(sb != -1 && sb < mn){
			mn = sb;
			ans1 = s2,ans2 = s1;
		}
	}
	int dig = bfs(ans1,ans2);
	vector<string> v;
	string cans2 = ans2;
	while(cans2 != ans1){
		v.push_back(cans2);
		cans2 = pre[cans2];
	} 
	v.push_back(ans1);
	reverse(v.begin(),v.end());
	for(int i = 0;i < v.size() - 1;i ++){
		cout << v[i] << " "; 
		if(i != v.size() - 1) cout << v[i + 1] << " ";
	}
	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
  • 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
  • 74
  • 75
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/617025
推荐阅读
相关标签
  

闽ICP备14008679号