优快云周赛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