2025.1.17——1200
2025.1.17——1200
Q1. 1200
Jellyfish has
They will play a game with
- If
is odd, Jellyfish can choose to swap one of her apples with one of Gellyfish's apples or do nothing. - If
is even, Gellyfish can choose to swap one of his apples with one of Jellyfish's apples or do nothing.
Both players want to maximize the sum of the values of their apples.
Since you are one of the smartest people in the world, Jellyfish wants you to tell her the final sum of the value of her apples after all
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case contains three integers,
The second line of each test case contains
The third line of each test case contains
Do note that the sum of
Q2. 1200
Andrey is just starting to come up with problems, and it's difficult for him. That's why he came up with a strange problem about permutations
Let's call the cost of a permutation
Find the maximum cost among all permutations of length
Input
Each test consists of multiple test cases. The first line contains a single integer
The only line of each test case contains a single integer
It is guaranteed that the sum of
Q3. 1200
Monocarp is going to make a purchase with cost of exactly
He has two types of coins, in the following quantities:
- coins worth
burle: regular coins and infinitely many fancy coins; - coins worth
burles: regular coins and infinitely many fancy coins.
Monocarp wants to make his purchase in such a way that there's no change — the total worth of provided coins is exactly
What's the smallest total number of fancy coins he can use to make a purchase?
Input
The first line contains a single integer
The only line of each testcase contains four integers
Q4. 1300
Cats are attracted to pspspsps, but Evirir, being a dignified dragon, is only attracted to pspspsps with oddly specific requirements...
Given a string
- If
is p, then forms a permutation (of length ); - If
is s, then forms a permutation (of length ); - If
is ., then there is no additional restriction.
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case contains a single integer
The second line of each test case contains a string
It is guaranteed that the sum of
Q5. 1300
You are given an array
Each query is represented by two integers
; ; .
In other words, for each query, you need to find a pair of different elements among
Input
The first line of the input contains a single integer
The first line of each test case contains a single integer
The second line of each test case contains
The third line of each test case contains a single integer
The next
It is guaranteed that the sum of the values of
------------------------思考------------------------
-
贪心博弈+guess+数学+发现结论+思维
A1
- 贪心博弈:发现策略为将自己最小与其最大交换/不操作。
A2
- 神秘题:严谨证明太难,只能靠手玩/天马行空/打表/guess。
A3
- 有趣的数学题:贪心再数学,考虑回退。
- 另解可对函数二分
A4
- 观察各种情况发现结论。
A5
- 巧妙的思维,维护少许东西就可以作出回答。
- 原题区间询问可看作(充分必要):
中是否存在与 不相同的数。
------------------------代码------------------------
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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m, k;
cin >> n >> m >> k;
int res = 0;
vector<int> a{(int)1e10, 0};
vector<int> b = a;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
res += x;
a[0] = min(a[0], x);
a[1] = max(a[1], x);
}
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
b[0] = min(b[0], x);
b[1] = max(b[1], x);
}
res -= a[0] + a[1];
if (a[0] < b[1])
swap(a[0], b[1]);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if ((k ^ 1) & 1)
{
// bug(k);
if (b[0] < a[1])
swap(b[0], a[1]);
}
res += a[0] + a[1];
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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
a[i] = i;
auto get = [&]()
{
int res = 0, mx = 0;
for (int i = 1; i <= n; i++)
res += a[i] * i, mx = max(mx, a[i] * i);
return res - mx;
};
int res = get();
for (int i = n - 1; i; i--)
{
for (int j = i; j < n; j++)
swap(a[j], a[j + 1]);
res = max(res, get());
// for (int i = 1; i <= n; i++)
// cout << a[i] << " ";
// cout << endl;
}
cout << res << 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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int m, k, a1, ak;
cin >> m >> k >> a1 >> ak;
int res = 0;
int m1 = m, m2 = 0;
if (ak)
m1 = max(0ll, m - k * min(ak, m / k));
if (m1)
m2 = max(0ll, m1 - a1);
if (m2)
{
res = m2 / k + m2 % k;
if (m1 / k - m2 / k)
res = min(res, m2 / k + 1);
}
cout << res << endl;
}
// void _()
// {
// int m, k, a1, ak;
// cin >> m >> k >> a1 >> ak;
// int res = 0;
// if (ak)
// m = max(0ll, m - ak * min(k, (m + ak - 1) / ak));
// if (m)
// m = max(0ll, m - a1);
// if (m)
// {
// res = m / k + m % k;
// if ((m / k + 1) * k <= m)
// res = min(res, m / k + 1);
// }
// cout << res << endl;
// }
A4
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC) \
cout << "bug:# "; \
for (auto val : VEC) \
cout << val << ' '; \
el;
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;
}
void _()
{
int n;
cin >> n;
string s;
cin >> s;
s.front() = s.front() == '.' ? 's' : s.front();
s.back() = s.back() == '.' ? 'p' : s.back();
bool f = 0;
map<char, int> cnt;
for (auto v : s)
cnt[v]++;
if (!cnt['p'] || !cnt['s'])
f = 1;
if (cnt['p'] == 1 && s.back() == 'p')
f = 1;
if (cnt['s'] == 1 && s.front() == 's')
f = 1;
cout << (f ? "YES" : "NO");
el;
}
A5
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC) \
cout << "bug:# "; \
for (auto val : VEC) \
cout << val << ' '; \
el;
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;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1), f(n + 1, -1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
f[i] = a[i] == a[i - 1] ? f[i - 1] : i - 1;
}
int q;
cin >> q;
while (q--)
{
int l, r;
cin >> l >> r;
int resl = -1, resr = -1;
if (f[r] >= l)
resl = f[r], resr = r;
cout << resl << ' ' << resr;
el;
}
el;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!