标签:main == max 就是 priority cto beautiful def --
A.Beautiful String
分析:这个题扫一遍就好了,看看能不能放,放就完事了,最后检验一下是不是合法的。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
char s[maxn];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%s", s + 1);
int n = strlen(s + 1);
s[0] = ‘z‘;
for (int i = 1; i <= n; i++) {
if (s[i] == ‘?‘) {
for (int c = ‘a‘; c <= ‘c‘; c++) {
if (c != s[i - 1] && c != s[i + 1]) {
s[i] = c;
break;
}
}
}
}
bool f = true;
for (int i = 1; i <= n; i++) {
if (s[i] == s[i + 1]) {
f = false;
break;
}
}
if (f)
printf("%s\n", s + 1);
else
printf("-1\n");
}
return 0;
}
B.Beautiful Numbers
分析:这个题找到1的位置,然后往两边延申一下弄一下就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+7;
int a[maxn];
int res[maxn];
priority_queue<int,vector<int>,less<int> > pq;
int main(){
int t,n;
cin>>t;
while(t--) {
while (!pq.empty()) pq.pop();
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int l = 0, r = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) {
l = i, r = i;
break;
}
}
res[1] = 1;
int cnt = 1;
for (int i = 2; i <= n; i++) {
if (l > 1 && r < n) {
if (a[l - 1] < a[r + 1]) {
l--;
if (a[l] <= i) cnt++;
else pq.push(a[l]);
} else {
r++;
if (a[r] <= i) cnt++;
else pq.push(a[r]);
}
} else {
if (l <= 1) {
r++;
if (a[r] <= i) cnt++;
else pq.push(a[r]);
} else {
l--;
if (a[l] <= i) cnt++;
else pq.push(a[l]);
}
}
while (!pq.empty() && pq.top() <= i) {
cnt++;
pq.pop();
}
if (cnt == i) res[i] = 1;
else res[i] = 0;
}
for (int i = 1; i <= n; i++)
printf("%d", res[i]);
printf("\n");
}
return 0;
}
C.Beautiful Regional Contest
分析:先使得金牌尽可能地少,就是题量最多的那一堆人,让他们得金牌。然后往后再扫一扫让银牌尽可能地少,只要比金牌多然后合法就截止了,最后剩下的能让他得铜牌就得铜牌就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+7;
int a[maxn],n;
int main() {
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int s = 1, g = 1, b = 0, i;
for (i = 1; i < n / 2; i++) {
if (a[i] != a[i - 1])
break;
g++;
}
for (i++; i < n / 2; i++) {
if (s > g && a[i] != a[i - 1])
break;
s++;
}
int j = i - 1;
while (i < n / 2) {
while (i < n - 1 && a[i + 1] == a[i])
i++;
if (i < n / 2) b = i - j;
i++;
}
if (s <= g || b <= g || !s || !g || !b) {
printf("0 0 0\n");
} else {
printf("%d %d %d\n", g, s, b);
}
}
return 0;
}
Codeforces Round #604 (Div. 2)
标签:main == max 就是 priority cto beautiful def --
原文地址:https://www.cnblogs.com/SwiftAC/p/12101221.html