Codeforces Round 993 (Div. 4)
Codeforces Round 993 (Div. 4)
2024.12.15 rank289 +123:1381->1504
A
Cube is given an integer
B
A string consisting of only characters 'p', 'q', and 'w' is painted on a glass window of a store. Ship walks past the store, standing directly in front of the glass window, and observes string
Ship gives you string
C
Ball is the teacher in Paperfold University. The seats of his classroom are arranged in
Ball is teaching
What is the maximum number of monkeys that Ball can seat?
D
Given a sequence of positive integers, a positive integer is called a mode of the sequence if it occurs the maximum number of times that any positive integer occurs. For example, the mode of
You gave UFO an array
However, UFO doesn't know how to construct array
E
Wave is given five integers
. .- There exists a non-negative integer
such that .
G1
This is the easy version of the problem. The key difference between the two versions is highlighted in bold.
A group of
The process is stable in the current year if each spider has the same number of plushies (before the current year's exchange) as he did the previous year (before the previous year's exchange). Note that year
Find the first year in which the process becomes stable.
------------------------独自思考分割线------------------------
-
nice!!
A
- 发现答案为n-1。
B
- 首先字符反转,p/q再反转。
C
- 贪心a,b,再贪心c。
D
- 比较有意思的构造。
E
- 暴力思路肯定会T,考虑优化:发现合法的对于每个k,合法区间
。 - 同时k的取值很小。考虑两次二分找合法范围。
G1
- 模拟过程找到循环。
------------------------代码分割线------------------------
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;
cin >> n;
cout << n - 1 << 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 _()
{
string s;
cin >> s;
reverse(s.begin(), s.end());
for (auto &v : s)
if (v - 'w')
v = v == 'p' ? 'q' : 'p';
cout << s << 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 _()
{
int m, a, b, c;
cin >> m >> a >> b >> c;
int res = 0, n1 = m, n2 = m;
res += min(n1, a);
n1 -= min(n1, a);
res += min(n2, b);
n2 -= min(n2, b);
res += min(n1 + n2, c);
cout << res << 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 _()
{
int n;
cin >> n;
vector<int> a(n);
map<int, int> has, in;
for (int &v : a)
cin >> v, has[v] = 1;
queue<int> no_has;
for (int i = 1; i <= n; i++)
if (!has[i])
no_has.push(i);
for (int i = 0; i < n; i++)
if (i)
{
if (a[i] == a[i - 1] || in[a[i]])
{
cout << no_has.front() << ' ';
in[no_has.front()] = 1;
no_has.pop();
}
else
cout << a[i] << ' ', in[a[i]] = 1;
}
else
cout << a[i] << " ", in[a[i]] = 1;
cout << 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 _()
{
int k, l1, r1, l2, r2;
cin >> k >> l1 >> r1 >> l2 >> r2;
int base = 1;
int res = 0;
for (; l1 * base <= r2; base *= k)
{
int l = l1 - 1, r = r1 + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (mid * base <= r2)
l = mid;
else
r = mid;
}
// bug2(l, l * base);
int u = l;
if (u < l1)
continue;
l = l1 - 1, r = u + 1;
while (r - l - 1)
{
int mid = l + r >> 1;
if (mid * base >= l2)
r = mid;
else
l = mid;
}
if (r > u)
continue;
res += u - r + 1;
}
cout << res << endl;
}
G1
#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;
vector<int> a(n + 1);
map<int, int> has;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
has[a[i]]++;
}
vector<int> no_has;
for (int i = 1; i <= n; i++)
if (!has[i])
no_has.push_back(i);
for (int i = 2;; i++)
{
if (no_has.size() == 0)
{
cout << i << endl;
return;
}
vector<int> vec;
for (auto v : no_has)
{
has[a[v]]--;
if (has[a[v]] == 0)
vec.push_back(a[v]);
}
no_has = vec;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!