2025.1.14——1200
2025.1.14——1200
Q1. 1200
You have
You want to choose exactly
You have to calculate the number of ways to choose exactly
Input
- the first line contains one integer
( ); - the second line contains
integers ( ).
Q2. 1200
Masha and Olya have an important team olympiad coming up soon. In honor of this, Masha, for warm-up, suggested playing a game with Olya:
There is an array
Masha aims to maximize the final number, while Olya aims to minimize it.
Masha and Olya decided to play on each non-empty prefix of the initial array
For each
Input
The first line of each test case contains a single integer
The second line contains
Q3. 1200
Vlad found a string
To do this, he can remove any pair of adjacent characters from
What is the minimum length Vlad can achieve by applying any number of deletions?
Input
The first line of each test case contains a single integer
The second line of each test case contains the string
Q4. 1200
Monocarp tries to get home from work. He is currently at the point
Unfortunately, it is late in the evening, so it is very dark. Monocarp is afraid of the darkness. He would like to go home along a path illuminated by something.
Thankfully, there are two lanterns, located in the points
You have to choose the minimum non-negative value
The picture for the first two test cases
------------------------独自思考分割线------------------------
-
结论+博弈+结论+结论
A1.
- 发现贡献可以缩小选择范围:只有等腰或等边三角形。
- 组合一下计算方案数。
A2.
- 本质就是发现损失的原因和决策。
- 根据奇偶性博弈一下发现损失和奇数的个数有一定关系。
A3.
- 思考最后答案的形态是同一个字母。
- 充分性策略:考虑最多的那个字母,尽量去消去它,而且在其他字母存在的时候一定可以消去它。
- 未消完剩下的就是最优答案,消完再讨论下奇偶决定答案0/1。
A4.
- 必要性:
点与 点一定需要被照亮。 - 充分性:两点被同一灯照亮/两灯都有参与并且两灯有连接。
- 数学一下:两种情况两灯互换一下 四种结果取最小值。
------------------------代码分割线------------------------
A1.
#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;
map<int, int> cnt;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
cnt[x]++;
}
int res = 0;
auto cal = [](int n)
{
return n * (n - 1) * (n - 2) / 6;
};
int has = 0;
for (auto [x, k] : cnt)
{
if (k >= 2)
res += has * k * (k - 1) / 2;
if (k >= 3)
res += cal(k);
has += k;
}
cout << res << endl;
}
A2.
#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 sum = 0;
int odd = 0;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
sum += x;
odd += x & 1 != 0;
int k = 0;
if (i)
{
k = (odd + 2) / 3;
if (odd % 3 == 2)
k--;
}
cout << sum - k << ' ';
}
cout << endl;
}
A3.
#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;
map<char, int> cnt;
int max_cnt = 0;
string s;
cin >> s;
for (auto v : s)
{
cnt[v]++;
max_cnt = max(max_cnt, cnt[v]);
}
int res = max(0ll, max_cnt - (n - max_cnt));
if (n & 1)
res = max(1ll, res);
cout << res << endl;
}
A4.
#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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
#define x first
#define y second
void _()
{
pair<int, int> o, p, a, b;
o.x = o.y = 0;
cin >> p.x >> p.y >> a.x >> a.y >> b.x >> b.y;
auto d = [](pair<int, int> a, pair<int, int> b)
{
return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
};
double res = min(max(d(a, o), d(a, p)), max(d(b, o), d(b, p)));
res = min(res, max(d(a, b) / 2, min(max(d(a, o), d(b, p)), max(d(b, o), d(a, p)))));
cout << res << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!