大学生团体天梯赛(第一届,已完结)

题目地址:天梯赛

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int main() {
	puts("Hello World!");
	return 0;
} 

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int n, x;
char c;
void print(int i) {
	for(int j = 0; j < x - i; ++j) putchar(' ');
	for(int j = 2 * i - 1; j >= 1; --j) putchar(c);
	putchar('\n');
}
int main() {
	cin >> n >> c;
	while(++x) {
		if(2 * (x * x) - 1 > n) {
			--x;
			break;
		}
	}
	for(int i = x; i >= 1; --i) print(i);
	for(int i = 2; i <= x; ++i) print(i);
	cout << n - 2 * (x * x) + 1;
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
string s;
map<char, int> mp;
int main() {
	cin >> s;
	for(auto& x : s) ++mp[x];
    for(auto& [key, value] : mp) {
    	cout << key << ":" << value << endl;
    }
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int f;
int main() {
	cin >> f;
	cout << "Celsius = " << 5 * (f - 32) / 9; 
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int n, a, b;
string s;
map<int, pair<string, int>>mp;
int main() {
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> s >> a >> b;
		mp.insert({a, {s, b}});
	}
	cin >> n;
	while(n--) {
		cin >> a;
		cout << mp[a].first << " " << mp[a].second << endl;
	}
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
long long n, maxx, flag;
int main() {
	cin >> n;
	for(int i = 2; i <= sqrt(n); ++i) {
		if(n % i) continue;
		long long now = n, check = 0, j = i;
		while(!(now % j)) {
			now /= j, ++check, ++j;
		}
		if(check > maxx) maxx = check, flag = i;
	}
	if(maxx) {
		cout << maxx << endl ;
		for(int i = 0; i < maxx; ++i) {
			cout << (i ? "*" : "") << flag + i;
		}
	} else {
		cout << 1 << endl << n;
	}
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
unordered_map<char, string>mp{
	{'-', "fu"}, {'0', "ling"}, {'1', "yi"}, {'2', "er"}, {'3', "san"}, {'4', "si"}, {'5', "wu"}, {'6', "liu"}, {'7', "qi"}, {'8', "ba"}, {'9', "jiu"}
};
string s;
int main() {
	cin >> s;
	for(int i = 0; i < s.length(); ++i) {
		cout << mp[s[i]] << " \n"[i == s.length() - 1];
	}
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int a, b, sum, cnt = 1;
int main() {
	cin >> a >> b;
	for(int i = a; i <= b; ++i, ++cnt) {
		sum += i;
		cout << setw(5) << i;
		if(!(cnt % 5)) cout << endl;
	}
	if(--cnt % 5) cout << endl;
	cout << "Sum = " << sum;
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int n, m, s, d, u, v, w;
struct node {
	int to, value;
	bool operator < (const node A) const {
		return value > A.value;
	} 
};
int person[505], res[505], pre[505], dis[505], vis[505], sum[505];
vector<node> road[505];
priority_queue<node> Q;
void print(int x) {
	if(x == s) {
		cout << s;
		return;
	}
	print(pre[x]), cout << " " << x;
}
int main() {
	cin >> n >> m >> s >> d;
	for(int i = 0; i < n; ++i) {
		cin >> person[i];
	}
	while(m--) {
		cin >> u >> v >> w;
		road[u].push_back({v, w}), road[v].push_back({u, w});
	}
	memset(dis, 0x3f3f3f, sizeof(dis));
	dis[s] = 0, res[s] = 1, pre[s] = -1, sum[s] = person[s], Q.push({s, 0});
	while(!Q.empty()) {
		auto [nx, nv] = Q.top();
		Q.pop();
		if(vis[nx]) continue;
		vis[nx] = true;
		for(auto& [to, value] : road[nx]) {
			if(dis[nx] + value < dis[to]) {
				dis[to] = dis[nx] + value, pre[to] = nx, res[to] = res[nx], sum[to] = sum[nx] + person[to], Q.push({to, dis[to]});
			} else if(dis[nx] + value == dis[to]) {
				if(sum[nx] + person[to] > sum[to]) {
					sum[to] = sum[nx] + person[to], pre[to] = nx;
				}
				res[to] += res[nx];
			}
		}
	}
	cout << res[d] << " " << sum[d] << endl, print(d);
	return 0;
} 

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
string now;
int n, cnt, check_cnt;
const int N = 1e5 + 5;
struct Node{
	string address, next;
	int value;
}p[N], node, q[N];
bool a[N];
map<string, pair<int, string>> mp;
unordered_map<int, int> check;
int main() {
	cin >> now >> n;
	for(int i = 0; i < n ; ++i) {
		cin >> node.address >> node.value >> node.next;
		mp.insert({node.address, {node.value, node.next}});
	}
	while(now != "-1") {
		p[cnt].address = now, p[cnt].value = mp[now].first, ++check[fabs(p[cnt].value)];
		if(check[fabs(p[cnt].value)] > 1) {
			a[cnt] = true, q[check_cnt++] = p[cnt];
		}
		p[cnt].next = mp[now].second, now = p[cnt++].next;
	}
	for(int i = 0; i < cnt; ++i) {
		cout << p[i].address << " " << p[i].value << " ";
		if(i + 1 < cnt && a[i + 1]) {
			while(++i && i < cnt) if(!a[i + 1]) break;
			cout << p[i].next << endl;
		} else {
			cout << p[i].next << endl;
		}
	}
	if(check_cnt){
		for(int i = 0; i < check_cnt - 1; ++i) {
			cout << q[i].address << " " << q[i].value << " " << q[i + 1].address << endl;
		}
		cout << q[check_cnt - 1].address << " " << q[check_cnt - 1].value << " -1";
	}
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
struct Node{
	double a, b;
} p[1005];
int n;
double ans, d;
int main() {
	cin >> n >> d;
	for(int i = 0; i < n; ++i) {
		cin >> p[i].a;
	}
	for(int i = 0; i < n; ++i) {
		cin >> p[i].b;
	}
	sort(p, p + n, [](Node x, Node y) {
		return x.b / x.a > y.b / y.a; 
	});
	for(int i = 0; i < n; ++i) {
		if(p[i].a < d) {
			d -= p[i].a, ans += p[i].b;
		} else {
			ans += (p[i].b / p[i].a) * d;
			break;
		}
	}
	printf("%.2f", ans);
	return 0;
} 

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int n, x;
vector<int>a, ans;
void ldfs(int root, int end) {
	int lchild = root + 1, rchild = end;
	while(a[lchild] < a[root] && lchild <= end) ++lchild;
	while(a[rchild] >= a[root] && rchild > root) --rchild;
	if(lchild - rchild != 1) return;
	ldfs(root + 1, rchild);
	ldfs(lchild, end);
	ans.push_back(a[root]);
}
void rdfs(int root, int end) {
	int lchild = root + 1, rchild = end;
	while(a[lchild] >= a[root] && lchild <= end) ++lchild;
	while(a[rchild] < a[root] && rchild > root) --rchild;
	if(lchild - rchild != 1) return;
	rdfs(root + 1, rchild);
	rdfs(lchild, end);
	ans.push_back(a[root]);
}
void print() {
	cout << "YES" << endl << ans[0];
	for(int i = 1; i < n; ++i) cout << " " << ans[i];
}
int main() {
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> x, a.push_back(x);
	}
	ldfs(0, n - 1);
	if(ans.size() == n) {
		print(); 
		return 0;
	}
	ans.clear(), rdfs(0, n - 1);
	if(ans.size() == n) {
		print(); 
		return 0;
	}
	cout << "NO";
	return 0;
} 

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int n, m;
int main() {
	cin >> n >> m;
	vector<int> a(n), res, mid;
	vector<vector<int>> check(m + 1, vector<int>(n + 1));
	bool is_find = false;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	function<void(int, int)> dfs = [&](int need, int index) {
		if (is_find || check[need][index]) return;
		check[need][index] = 1;
		if (need == 0) {
			res = mid, is_find = true;
			return;
		}
		for (int i = index; i < n; ++i) {
			if (a[i] > need) break;
			mid.push_back(a[i]);
			dfs(need - a[i], i + 1);
			mid.pop_back();
		}
	};
	for (int i = 0; i < n; ++i) {
		if (a[i] > m) break;
		mid.push_back(a[i]);;
		dfs(m - a[i], i + 1);
		mid.pop_back();
	}
	if (res.empty()) {
		puts("No Solution");
	} else {
		for (int i = 0; i < res.size(); ++i) {
			cout << res[i] << " \n"[i == res.size() - 1];
		}
	}
	return 0;
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int tr[N], n, x;
stack<int> st;
string s;
int lowbit(int x) {
	return x & -x;
}
void insert(int x, int v) {
	for(int i = x; i < N; i += lowbit(i)) {
		tr[i] += v;
	}
}
int sum(int x) {
	int cnt = 0;
	for(int i = x; i; i -= lowbit(i)) {
		cnt += tr[i];
	}
	return cnt;
}
int main() {
	cin >> n;
	while(n--) {
		cin >> s;
		if(s == "Push") {
			cin >> x;
			st.push(x), insert(x, 1);
		} else if(s == "Pop") {
			if(st.empty()) {
				cout << "Invalid" << endl;
				continue;
			}
			x = st.top(), st.pop();
		 	insert(x, -1);
			cout << x << endl;
		} else {
			if(st.empty()) {
				cout << "Invalid" << endl;
				continue;
			}
			x = ((st.size() + 1) >> 1);
			int left = 0, right = N - 1, ans;
			while(left <= right) {
				int mid = left + ((right - left) >> 1);
				if(sum(mid) >= x) {
                    ans = mid, right = mid - 1;
				} else {
				    left = mid + 1;
				}
			}
            cout << ans << endl;
		}
	}
}

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int f[1005];
int n, k, x;
unordered_map<int, int> mp;
int find(int x) {
	return x == f[x] ? x : f[x] = find(f[x]);
}
void merge(int x, int y) {
	f[find(x)] = find(y);
}
int main() {
	cin >> n;
	vector<vector<int>> person(n + 1);
	for(int i = 1; i <= 1000; ++i) {
		f[i] = i;
	}
	for(int i = 1; i <= n; ++i) {
		cin >> k, getchar();
		for(int j = 0; j < k; ++j) {
			cin >> x;
			person[i].push_back(x), merge(x, person[i][0]);
		}
	}
	for(int i = 1; i <= n; ++i) {
        ++mp[find(person[i][0])];
	}
	vector<int> res;
	for(auto& y : mp) {
		res.emplace_back(y.second);
	}
	sort(res.begin(), res.end(), greater<int>());
	cout << res.size() << endl;
	for(int i = 0; i < (int)res.size(); ++i) {
		cout << (i ? " " : "") << res[i];
	}
	return 0;
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东大21计科小萌新

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值