Educational Codeforces Round 119 (Rated for Div. 2)
Educational Codeforces Round 119 (Rated for Div. 2)
A. Equal or Not Equal
题意:有一数列成环状排列(首尾相接)现给出相邻位置是否相等的信息,问满足条件的环状数列是否存在
#include "bits/stdc++.h"
using namespace std;
const int N = 60;
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
char s[N];
cin >> (s + 1);
int siz = strlen(s + 1);
int cnt = 0;
for (int i = 1; i <= siz; ++i) {
if (s[i] == 'N') cnt++;
}
if (cnt == 1) cout << "NO" << endl;
else cout << "YES" << endl;
}
}
B. Triangles on a Rectangle
题意:给出一个大的 w × h w\times h w×h的矩形,并给出每条边上的点的位置,保证每条边上的点至少有2个,求满足1.有两个点在同一条边上;2.面积最大 的三角形的面积的两倍
直接枚举底边为哪个边,由于每条边上必然有至少两个点,高一定是w或h
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
ll T;
cin >> T;
while (T--) {
ll w, h;
cin >> w >> h;
ll ans = 0;
for (ll i = 1; i <= 4; ++i) {
ll k;
cin >> k;
ll hi;
if (i == 1 || i == 2) hi = h;
else hi = w;
ll x, y;
cin >> x;
for (ll j = 1; j < k; ++j) {
cin >> y;
}
ll tmp = (y - x) * hi;
ans = max(ans, tmp);
}
cout << ans << endl;
}
return 0;
}
C. BA-String
题意:有一个字符串,由a
和*
组成,可以将一个*
替换成0到k中任意数目的b
,问所有满足条件的串中第x大的串是什么
将所有*..*
的位置扣出来,每个位置假设为num个*
,这里能取的b
则为
n
u
m
×
k
+
1
num\times k +1
num×k+1种,即为在算所有串的种数的时候这里的贡献,同时由于原串中不变的位置全为a
,插入的全为b
,考虑字典序递增的字符串必是先由后边在变。
可以看做是一个每个位 进制不同的 大数
参考进制转换的做法
注意string的直接+(append的+)速度非常慢,会超时。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2010;
char s[N];
struct node {
char ch;
ll num;
};
signed main() {
// ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T;
// cin >> T;
scanf("%d", &T);
while (T--) {
ll n, k, x;
// cin >> n >> k >> x;
scanf("%lld%lld%lld", &n, &k, &x);
x--;
scanf("%s", s);
ll cnt = 0;
vector<node> vec;
for (ll i = n - 1; i >= 0; --i) {
if (s[i] == '*') {
cnt += k;
} else {
if (cnt > 0) {
ll num = x % (cnt + 1);
x = x / (cnt + 1);
// for (ll j = 0; j < num; ++j) {
// ans = ans + 'b';
// }
vec.push_back({'b', num});
}
cnt = 0;
// ans = ans + 'a';
vec.push_back({'a', 1});
}
}
if (cnt > 0) {
ll num = x % (cnt + 1);
x = x / (cnt + 1);
// for (ll j = 0; j < num; ++j) {
// ans = ans + 'b';
// }
vec.push_back({'b', num});
}
// ll siz = ans.size();
// for (ll i = siz - 1; i >= 0; --i) putchar(ans[i]);
int siz = vec.size();
for (int i = siz - 1; i >= 0; --i) {
char ch = vec[i].ch;
int num = vec[i].num;
for (int j = 0; j < num; ++j) {
putchar(ch);
}
}
puts("");
}
return 0;
}
D
E出的多先E了,挖坑改天补D
E. Replace the Numbers
题意:刚开始有个空的数组,有两种操作,
1 x
表示 将x添在数组末尾
2 x y
表示将数组中当前所有的x替换为y
考虑倒着做,维护一个p[]数组,p[x]表示x被替换成了什么
两种操作变成 1:将p[x]添在数组末尾,2:将p[x]由p[y]替换
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
int p[N];
vector<int> vec;
struct node {
int t, x, y;
};
node mp[N];
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
for (int i = 0; i < N; ++i) p[i] = i;
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
cin >> mp[i].t >> mp[i].x;
if (mp[i].t == 2) cin >> mp[i].y;
}
for (int i = q; i >= 1; --i) {
int t = mp[i].t;
if (t == 1) {
int x = mp[i].x;
vec.push_back(p[x]);
} else {
int x = mp[i].x, y = mp[i].y;
p[x] = p[y];
}
}
int siz = vec.size();
for (int i = siz - 1; i >= 0; --i) {
cout << vec[i] << " ";
}
cout << endl;
return 0;
}