优快云周赛33题解奇偶排序、小艺改编字符串、公司新表、选择客栈

优快云周赛33题解

T1奇偶排序

#include <bits/stdc++.h>
using namespace std;
int a[10010], b[10010];
int main()
{
	int n, t;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int idx = 1;
	for (int i = 1; i <= n; ++i) {
		if (a[i] % 2) b[idx++] = a[i];
	}
	for (int i = 1; i <= n; ++i) {
		if (a[i] % 2 == 0) b[idx++] = a[i];
	}
	for (int i = 1; i <= n; ++i) {
		cout << b[i] << " ";
	}
	return 0;
}

T2小艺改编字符串

#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int n = s.size();
	vector<vector<int>> dp(n, vector<int>(n, 0));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = i + 1; j < n; ++j) {
			if (s[i] == s[j]) {
				dp[i][j] = dp[i + 1][j - 1];
			}
			else dp[i][j] = min(dp[i + 1][j] + 1, dp[i][j - 1] + 1);
		}
	}
	cout << dp[0][n - 1];
	return 0;
}

T3公司新表

#include <bits/stdc++.h>
using namespace std;
bool is_ok(vector<int> time, int p, int up) {
	int res = 0, t = 1;
	for (auto it = time.rbegin(); it != time.rend(); ++it) {
		if (*it >= p) return false;
		res += *it * t;
		t *= p;
	}
	if (res <= up) return true;
	else return false;
}

int main()
{
	vector<int> H, S;
	string s;
	bool f = true;
	cin >> s;
	for (int i = 0; i < (int)s.size(); ++i) {
		char t = s[i];
		if (t != ':' && f) {
			if (t == '0') continue;
			if (isdigit(t)) H.push_back(t - '0');
			else H.push_back(t - 'A' + 10);
		}
		else if (t == ':') {
			f = false;
		}
		else {
			if (t == '0') continue;
			if (isdigit(t)) S.push_back(t - '0');
			else S.push_back(t - 'A' + 10);
		}
	}
	bool tt = false;
	if (is_ok(H, 60, 23) && is_ok(S, 60, 59)) cout << -1;
	else {
		for (int i = 2; i <= 59; ++i) {
			if (is_ok(H, i, 23) && is_ok(S, i, 59)) {
				cout << i << " ";
				tt = true;
			}
		}
		if (tt == false) cout << 0;
	}
	return 0;
}

T4选择客栈

https://www.acwing.com/problem/content/description/502/
https://www.luogu.com.cn/problem/P1311

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值