2025.2.9——1400
1.2025.2.19——15002.11.23 周六3.11.24 周日4.11.25 周一日常5.2024.11.26 周二日常6.2024.11.27 周三7.2024.11.28周四8.2024.11.29 周五9.2024.11.30 周六10.2024.12.1 周日11.2024.12.2 周一12.2024.12.3 周二13.2024.12.4 周三14.2024.12.5 周四15.2024.12.7 周六16.2024.12.8 周日17.2024.12.9 周一18.2024.12.10 周二19.2024.12.11 周三20.2024.12.12 周四21.2024.12.13 周五22.2024.12.14 周六23.2024.12.16 周一24.2024.12.17 周二25.2024.12.18 周三26.2024.12.19 周四27.2024.12.20 周五28.2024.12.21 周六29.2024.12.22 周日30.2024.12.23 周一31.2024.12.24 周四32.2024.12.25 周三33.2024.12.26 周四34.2024.12.27 周五35.2024.12.28 周六36.2024.12.29 周日37.2024.12.30 周一38.2025.1.5——120039.2025.1.12——120040.2025.1.14——120041.2025.1.15——120042.2025.1.16——120043.2025.1.17——120044.2025.1.18——130045.2025.1.19——130046.2025.1.20——130047.2025.1.21——130048.2025.1.22——130049.2025.1.24——140050.2025.1.26——140051.2025.2.8——1400
52.2025.2.9——1400
53.2025.2.10——140054.2025.2.14——140055.2025.2.15——140056.2025.2.17——14002025.2.9——1400
A 1400
B 1400
C 1400
D 1400
E 1400
------------------------------------------------
-
二进制/贪心+博弈/结论+结论/贪心/栈+二分+字符串
A
- 入手:分别考虑每一位。
- 关键:贪心。
- 巧妙:交换。
B
- 关键:换一种方式考虑每一个选与不选对答案的影响,从而发现结论。
C
- 入手:
时模拟发现。 - 关键:贪心匹配的方式,排序后对于每一个
匹配最近且未配对的 。 - 巧妙:用栈去优化配对方式。
D
- 入手:二分很明显。
- 关键:维护一个区间而不是一个点。
- 巧妙:一种代码适用于两种情况。
E
- 入手:模拟一下。每次操作使子串中的最后一个字母去掉。
- 关键:必要次数将单调不增的子串操作至单调不减。次数为原始长度-前缀相同的个数。
------------------------代码------------------------
A
#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, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
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 a, b, r;
cin >> a >> b >> r;
if (a < b)
swap(a, b);
bool fir = 1;
int res = 0;
for (int i = 60; i >= 0; i--)
{
int bit_a = a >> i & 1;
int bit_b = b >> i & 1;
if (bit_a - bit_b)
{
if (fir)
{
fir = 0;
res += 1ll << i;
}
else
{
if (bit_b)
res -= 1ll << i;
else if (r - (1ll << i) >= 0)
res -= 1ll << i, r -= 1ll << i;
else
res += 1ll << i;
}
}
}
cout << res;
el;
}
B
#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, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
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;
struct Node
{
int a, b;
};
vector<Node> a(n);
for (auto &[a, b] : a)
cin >> a;
for (auto &[a, b] : a)
cin >> b;
sort(a.begin(), a.end(), [](Node &e1, Node &e2)
{ return e1.a + e1.b > e2.a + e2.b; });
int res = 0;
int f = 1;
for (auto [x, y] : a)
{
if (f)
res += x - 1;
else
res -= y - 1;
f ^= 1;
}
cout << res;
el;
}
C
#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, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
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<pair<int, int>> a(n << 1);
vector<int> w(n);
int cnt = n;
for (auto &[x, y] : a)
{
cin >> x;
y = cnt > 0 ? 1 : -1;
cnt--;
}
for (auto &x : w)
cin >> x;
sort(w.begin(), w.end());
sort(a.begin(), a.end());
vector<int> stk, len;
for (auto [x, y] : a)
{
if (y == 1)
stk.push_back(x);
else
{
len.push_back(x - stk.back());
stk.pop_back();
}
}
sort(len.rbegin(), len.rend());
int res = 0;
for (int i = 0; i < n; i++)
res += len[i] * w[i];
cout << res;
el;
}
D
#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, ST) \
{ \
for (int I = ST; I < VEC.size(); I++) \
cout << VEC[I] << ' '; \
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<pair<int, int>> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i].first >> a[i].second;
auto ok = [&](int x)
{
int l = 0, r = 0;
for (int i = 1; i <= n; i++)
{
l = max(a[i].first, l - x); // 找到一种方式适用于两种情况
r = min(a[i].second, r + x);
if (l > r)
return 0;
}
return 1;
};
int l = -1, r = 1e12;
while (r - l - 1)
{
int mid = l + r >> 1;
if (ok(mid))
r = mid;
else
l = mid;
}
cout << r;
el;
}
E
#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) \
{ \
for (auto Vec : VEC) \
cout << Vec << ' '; \
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;
string t = s;
sort(t.begin(), t.end());
if (t == s)
{
cout << 0;
el;
return;
}
char op = s[n - 1];
vector<int> id{n - 1};
for (int i = n - 2; i >= 0; i--)
if (s[i] >= s[id.back()])
id.push_back(i);
int res = id.size() - 1;
for (int i = id.size() - 2; i >= 0; i--)
if (s[id[i]] == s[id[id.size() - 1]])
res--;
else
break;
for (int l = 0, r = id.size() - 1; l < r; l++, r--)
swap(s[id[l]], s[id[r]]);
// bugv(id);
// bug(s);
t = s;
sort(t.begin(), t.end());
if (t != s)
res = -1;
cout << res;
el;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!