附加题单1:)
第一次AK代码源的题单:)(其实D是看题解的
因为CF炸了还没修好写不了题导致wyn闲的没事做跑来写总结。。:)
A - Inversion Pairs
这题我第二个过!!(第一个过的不是人,39s就A了qwq
写了15分钟,WA 1发:)
不难发现,根据贪心的思想,把所有问号抠出来之后肯定是前面一坨1后面一坨0,于是我们可以想到枚举最后一个1的位置,边枚举边算最后一个1在这里时的答案,然后就一点都不顺利的AC叻:)
一点都不顺利(WA 1发)是因为:
不开long long见祖宗!!
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int t, n;
string s;
int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for (cin >> t; t--;) {
cin >> n >> s;
s = ' ' + s;
LL sum = 0, tmp = 0, ans = 0, s1 = 0;
for (int i = 1; i <= n; i++) {
if (s[i] == '0' || s[i] == '?') {
sum++;
tmp += s1;
} else {
s1++;
}
}
s1 = 0;
ans = tmp;
for (int i = 1; i <= n; i++) {
if (s[i] == '?') {
tmp -= s1;
s1++;
sum--;
tmp += sum;
} else if (s[i] == '0') {
sum--;
} else {
s1++;
}
ans = max(ans, tmp);
}
cout << ans << "\n";
}
return 0;
}B - Distributed System
写了15分钟,没吃罚时:)
不难发现,每个任务都是先给所有工作节点+1,然后再给最后的几个和开头的几个+1,所以直接用差分写完叻,好耶:)
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL t, n, q, a[200010];
int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for (cin >> t; t--;) {
cin >> n >> q;
fill(a, a + n, 0);
LL ans = 0;
for (LL x, y; q--;) {
cin >> x >> y;
ans += x / n;
x %= n;
a[y]++;
a[min(n, y + x)]--;
a[0]++;
a[max(0ll, x + y - n)]--;
}
LL sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
cout << ans + sum << ' ';
}
cout << "\n";
}
return 0;
}C - 树论函数
写了30分钟,没吃罚时:)
一看题面就被吓跑了,写J去了
写这个题之前我还是第1的,写完J一看天塌了我怎么掉下去叻,再看了眼这题我直接炸了啊,我要是写这个没准能在第1多苟一会qwq
看上去很吓人,但其实只要输出r - l + 1 qwq实在是太糖了
写之前十分倔强的想要证明(他们都说是这样但不屑于不知道证明)就自己证了一下,给证出来了:因为所以那么我们就可以连一个到的和一个到的,这样和就联通叻,然后所有点就都能联通叻:)
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int t, s, l, r;
int main () {
for (cin >> t; t--;) {
cin >> s >> l >> r;
cout << r - l + 1 << "\n";
}
return 0;
}D - Good Matrix
不会做,赛后看懂了题解随便写写交了上去,结果CF炸了测不了,也不知道A了没有qwq
E - Problem Setting
写了11分钟,WA了1发,CE了1发qwq
我觉得这道题比F简单,怎么做的人更少??
直接处理出每个属性最终应该在的最小的区间,然后算一下从它的属性值到区间的距离就行了:)
我也不会告诉你WA 1发和CE 1发都是因为:
不开long long见祖宗
祖宗见我都见烦了qwq
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL t, n, q, a[110];
struct qwq {
LL l, r;
} b[110];
int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for (cin >> t; t--;) {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i].l = 0;
b[i].r = 1e9;
}
for (LL p, l, r; q--;) {
cin >> p >> l >> r;
b[p].l = max(b[p].l, l);
b[p].r = min(b[p].r, r);
}
LL ans = 0;
for (int i = 1; i <= n; i++) {
if (b[i].l > b[i].r) {
ans = -1;
break;
}
if (a[i] < b[i].l) {
ans += b[i].l - a[i];
}
if (a[i] > b[i].r) {
ans += a[i] - b[i].r;
}
}
cout << ans << "\n";
}
return 0;
}F - easy
写了11分钟,没吃罚时:)
过的人最多的题竟然是我唯一没搞明白的题,我太菜了,心态崩了qwq
看了样例就盲猜是不是怎么选和都一样,试了一下,本来是想吃罚时的结果过了:):):)我直接就飞起来:)
所以有没有数学大佬能给这个彩笔解释一下为什么怎么选和都一样qwq
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n;
int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
cout << (n * n + 1) * n;
return 0;
}G - 删除01串
用上午的最后10分钟极限一遍过:)(真刺激
首先如果2端不一样那肯定enpty。然后就找到在最短的在2个单独的不等于a[1]的的字符中间连续的a[1]的长度输出就可以了
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int t, n;
string s;
int main () {
for (cin >> t; t--;) {
cin >> n >> s;
s = ' ' + s + ' ';
if (s[1] != s[n]) {
cout << "empty\n";
continue;
}
int tmp = 0, sum = 0, ans = n;
for (int i = 2; i <= n + 1; i++) {
if (s[i] != s[1]) {
ans = min(ans, i - tmp - 1);
tmp = i;
}
}
if (ans == 0) {
cout << "empty\n";
} else {
for (int i = 1; i <= ans; i++) {
cout << s[1];
}
cout << "\n";
}
}
return 0;
}H - 砝码
不知道写了多久,一遍过:)
枚举用多少个数来整二进制的方法,剩下的平均的搞,具体的见代码(其实是wyn语文太菜不会写了qwq
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int t, n, m;
int main () {
for (cin >> t; t--;) {
cin >> n >> m;
int ans = n + 1;
for (int i = 1; (1 << i - 1) - 1 < n && i <= m; i++) {
int tmp = max(0, n - (1 << i) + 1);
if (tmp == 0) {
ans = min(ans, (1 << i - 1));
break;
}
if (i == m) break;
int tmp1 = tmp / (m - i);
if (tmp1 * (m - i) < tmp) tmp1++;
if ((1 << i) - 1 < tmp1 - 1) continue;
ans = min(ans, max((1 << i - 1), tmp1));
if ((1 << i - 1) >= tmp1) break;
}
if (ans == n + 1) {
cout << "-1\n";
continue;
}
cout << ans << "\n";
}
return 0;
}I - 游戏高手
写了39分钟,没WA:)
写完发现!第1!第1次第1!!!:):):):)
我太菜了心态崩了
先枚举不同的字符数,然后就可以双指针:)
屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n, f[30], ans1, ans2;
string s;
int main () {
cin >> s;
n = s.size();
s = ' ' + s;
for (int i = 1; i <= 26; i++) {
// cout << i << ' ' << ans1 << ' ' << ans2 << "\n";
fill(f, f + 26, 0);
int j = 0, sum = 0;
for (; sum < i && j < n;) {
f[s[++j] - 'a']++;
if (f[s[j] - 'a'] == 1) sum++;
}
if (sum < i) break;
for (int l = 1; j <= n; j++) {
for (; (f[s[l] - 'a'] > 1 || sum > i) && l <= j;) {
f[s[l++] - 'a']--;
if (f[s[l - 1] - 'a'] == 0) sum--;
}
// cout << ans1 << ' ' << ans2 << ' ' << l << ' ' << j << "\n";
if (ans2 == 0 || (j >= l && (double)(ans1 * ans1) / ans2 < (double)(i * i) / (j - l + 1))) {
ans1 = i;
ans2 = j - l + 1;
}
if (j < n) {
f[s[j + 1] - 'a']++;
if (f[s[j + 1] - 'a'] == 1) {
sum++;
}
}
}
}
cout << ans1 * ans1 / __gcd(ans1 * ans1, ans2) << ' ' << ans2 / __gcd(ans1 * ans1, ans2);
return 0;
}J - 四舍五入
写了70分钟,没吃罚时:)
不难发现,大于或等于444…44(y - 1个4)500…0的数都是合法的:)
然后求个和就完了:)
个人认为此题单最屎山的屎山:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL x, y, mod = 998244353;
LL qpow (LL x, LL y) {
LL ret = 1;
for (; y; y >>= 1) {
if (y & 1) {
ret *= x;
ret %= mod;
}
x *= x;
x %= mod;
}
return ret;
}
int main () {
cin >> x >> y;
y = min(y, x);
if (y < x) {
LL tmp = qpow(10, x - 1) * 5 % mod;
LL tmp1 = 0;
for (int i = 1; i < y; i++) {
tmp1 = tmp1 * 10 + 4;
tmp1 %= mod;
}
tmp1 = tmp1 * 10 + 5;
tmp1 %= mod;
tmp1 *= qpow(10, x - y - 1) * 5 % mod;
tmp1 %= mod;
tmp += tmp1;
tmp %= mod;
tmp1 = 0;
for (int i = 1; i <= y; i++) {
tmp1 = tmp1 * 10 + 5;
tmp1 %= mod;
}
tmp1 *= qpow(10, x - y);
tmp1++;
tmp1 %= mod;
tmp *= tmp1;
tmp %= mod;
tmp -= qpow(10, x);
tmp = (tmp + mod) % mod;
cout << tmp;
} else {
LL tmp = qpow(10, x);
LL tmp1 = 0;
for (int i = 1; i < x; i++) {
tmp1 = tmp1 * 10 + 4;
tmp1 %= mod;
}
tmp1 = tmp1 * 10 + 5;
tmp1 %= mod;
tmp += tmp1;
tmp %= mod;
tmp1 = 2;
for (int i = 1; i < x - 1; i++) {
tmp1 = tmp1 * 10 + 7;
tmp1 %= mod;
}
tmp1 = tmp1 * 10 + 8;
tmp1 %= mod;
if (x == 1) {
tmp1 = 3;
}
tmp = tmp * tmp1 % mod;
tmp -= qpow(10, x);
tmp += mod;
tmp %= mod;
cout << tmp;
}
return 0;
}写完总结叻:)
明天是我喜欢的歌手zs的出道日,模拟赛要好好打:)