2025.2.10——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——140052.2025.2.9——1400
53.2025.2.10——1400
54.2025.2.14——140055.2025.2.15——140056.2025.2.17——14002025.2.10——1400
A 1400
B 1400
C 1400
D 1400
------------------------------------------------
-
思维+前缀+数学+贪心/结论
A
- 入手点:发现
时答案为0。 - 关键点:考虑
时即可。 - 巧妙点:
去寻找第一个大于与小于指定值的数。
B
- 入手点:更换一种问题的计算方式,考虑一层层的后缀和。
- 关键点:正数求和。
- 对前缀和的理解。
C
- 入手:只需考虑最大值与最小值。
- 关键:每次操作会使差值/2。贪心奇偶数讨论一下即可。
D
- 关键:贪心单调匹配。
- 巧妙:使用结构体绑定下标排序,用于匹配。
------------------------代码------------------------
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) \
{ \
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, k;
cin >> n >> k;
vector<int> a(n);
int res = 1e18;
for (int i = 0; i < n; i++)
cin >> a[i], res = min(res, a[i]);
sort(a.begin(), a.end());
for (int i = 1; i < n; i++)
res = min(res, a[i] - a[i - 1]);
if (k == 2)
{
vector<int> inv = a;
reverse(inv.begin(), inv.end());
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
{
int v = abs(a[i] - a[j]);
auto it_r = lower_bound(begin(a), end(a), v);
auto it_l = lower_bound(begin(inv), end(inv), v, greater<int>());
if (it_r != end(a))
res = min(res, abs(*it_r - v));
if (it_l != end(inv))
res = min(res, abs(*it_l - v));
}
}
if (k > 2)
res = 0;
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) \
{ \
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;
vector<int> a(n + 1), suf(n + 2);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = n; i; i--)
suf[i] = suf[i + 1] + a[i];
int res = suf[1];
for (int i = 2; i <= n; i++)
res += suf[i] > 0 ? suf[i] : 0;
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) \
{ \
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;
int l = 1e12, r = -1;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
l = min(l, x);
r = max(r, x);
}
vector<int> res;
while (l - r)
{
int v = l & 1 ? 1 : 0;
res.push_back(v);
l += v, r += v;
l >>= 1, r >>= 1;
}
cout << res.size();
el;
if (res.size() <= n)
for (auto v : res)
cout << v << ' ';
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) \
{ \
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, k;
cin >> n >> k;
struct Node
{
/* data */
int v, id;
};
vector<Node> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i].v, a[i].id = i;
for (auto &[v, id] : b)
cin >> v;
sort(begin(a), end(a), [](Node &e1, Node &e2)
{ return e1.v < e2.v; });
sort(begin(b), end(b), [](Node &e1, Node &e2)
{ return e1.v < e2.v; });
int stb = -1;
for (int i = n - k; i < n; i++)
b[++stb].id = a[i].id;
for (int i = 0; i < n - k; i++)
b[++stb].id = a[i].id;
sort(begin(a), end(a), [](Node &e1, Node &e2)
{ return e1.id < e2.id; });
sort(begin(b), end(b), [](Node &e1, Node &e2)
{ return e1.id < e2.id; });
int cnt = 0;
for (int i = 0; i < n; i++)
cnt += a[i].v > b[i].v;
if (cnt - k)
{
cout << "NO";
el;
return;
}
cout << "YES";
el;
for (auto [v, id] : b)
cout << v << ' ';
el;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!