Codeforces Round 991 (Div. 3)
2024.12.6 rank 1559 rating 1314->1381
A
模擬
B
給定一陣列,你可以任意操作:a[i-1]+1&&a[i+1]-1 或者 a[i-1]-1&&a[i+1]+1。問是否可以使陣列全為相同的數字。
C
給定一大數,可任意將2->4,3->9,問是否可被9整除。
D
給定一大數,你可任意操作:將某一位數字減一將其與高位互換位置。問最大可成為的數字。
E
給定字串a,b,c。當a,b不空時,隨機選擇a/b的第一個字母放到空字串d後面。問將字串d修改最少的字母和c相等。
------------------------獨自思考分割線------------------------
-
唯一有挑戰性的題就是E吧
A 1點
1. 注意讀完資料
B 2點
1.需要發現數字的轉移只能在奇數/偶數項。
2.任意操作代表了可任意分配數字。則奇數偶數項分別求和分配即可。
C 3點
1.發現被9整除的數字數位之和為9的倍數。
2.在操作至多8個2和8個3看是否滿足。因為超過8個是無意義的,則兩側列舉暴力。
3.賽時分類討論數位和%9之後到達9的最小值分配2,3的數量,總感覺不太嚴謹的樣子。可以hack一下試試。
D 2點
1.發現每個位置做多隻和右側9個數字有關。列舉每一位找到其可變成的最大值。
2.在貢獻相同的情況下優先考慮左側的數字。
E 2點
1.dp:f[i][j]:考慮a前i個字母,b前j個字母形成c前i+j個字母所需要修改的最小字母個數。
2.邊界初始化
------------------------程式碼分割線------------------------
A
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 互動/除錯 關
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m;
cin >> n >> m;
int cnt = 0;
int f = 1;
while (n--)
{
string s;
cin >> s;
if (f && m >= s.size())
{
m -= s.size();
cnt++;
}
else
f = 0;
}
cout << cnt << endl;
}
B
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 互動/除錯 關
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
int s1 = 0, s2 = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (i & 1)
s1 += x;
else
s2 += x;
}
int f = 1;
if (s1 % (n + 1 >> 1) || s2 % (n >> 1))
f = 0;
if (s1 / (n + 1 >> 1) - s2 / (n >> 1))
f = 0;
cout << (f ? "YES" : "NO") << endl;
}
C
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 互動/除錯 關
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
string s;
cin >> s;
int sum = 0;
int c2 = 0, c6 = 0;
for (auto v : s)
{
if (v == '2')
c2++;
if (v == '3')
c6++;
sum += v - '0';
}
int x = sum % 9;
int f = 0;
auto ok1 = [&](int cnt)
{
return c2 >= cnt;
};
auto ok2 = [&](int cnt1, int cnt2)
{
return c2 >= cnt1 && c6 >= cnt2;
};
if (!x)
f = 1;
else if (x == 1)
{
if (c2 >= 4 || (c6 && c2))
f = 1;
}
else if (x == 2)
{
if (c2 >= 8 || (c2 >= 5 && c6) || (c2 >= 2 && c6 >= 2))
f = 1;
}
else if (x == 3)
{
if (ok1(3) || c6)
f = 1;
}
else if (x == 4)
{
if (ok1(7) || ok2(4, 1) || ok2(1, 2))
f = 1;
}
else if (x == 5)
{
if (ok1(2))
f = 1;
}
else if (x == 6)
{
if (ok1(6) || ok2(3, 1) || c6 >= 2)
f = 1;
}
else if (x == 7)
{
if (c2)
f = 1;
}
else if (x == 8)
{
if (ok1(5) || ok2(2, 1))
f = 1;
}
cout << (f ? "YES" : "NO") << endl;
}
D
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 互動/除錯 關
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++)
{
int j = min(n - 1, i + 9);
int jj = j;
int maxw = 0;
for (; j >= i; j--)
{
if (s[j] - (j - i) >= maxw)
{
maxw = s[j] - (j - i);
jj = j;
}
}
// bug(jj);
if (jj == i)
continue;
j = jj;
while (i - j)
{
swap(s[j], s[j - 1]);
s[j - 1]--;
j--;
}
// bug(s);
}
cout << s << endl;
}
E
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 互動/除錯 關
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
string a, b, c;
cin >> a >> b >> c;
int n = a.size(), m = b.size();
a = " " + a;
b = " " + b;
c = " " + c;
vector<vector<int>> f(n + 1, vector<int>(m + 1, 1e18));
f[0][0] = 0;
for (int i = 1; i <= n; i++)
f[i][0] = f[i - 1][0] + (a[i] != c[i]);
for (int j = 1; j <= m; j++)
f[0][j] = f[0][j - 1] + (b[j] != c[j]);
// f[1][0] = a[1] != c[1];
// f[0][1] = b[1] != c[1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
f[i][j] = min(f[i - 1][j] + (a[i] != c[i + j]), f[i][j - 1] + (b[j] != c[i + j]));
// bug3(i, j, f[i][j]);
}
cout << f[n][m] << endl;
}