2024.12.3 周二
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——140053.2025.2.10——140054.2025.2.14——140055.2025.2.15——140056.2025.2.17——14002024.12.3 周二
Q1. 1100
给定两个长度为n和n+1的数组a,b。每次操作:选择a的任意一个数 +1/-1/复制到末尾。
问将a变成b的最小操作次数。
Q2. 1200
设定一个数组是美丽的:当其可以通过任意次操作将数组里的数变成同一个数字,操作:如果a[i-1]==a[i+1],则可使a[i]=a[i-1]。
问删除数组里最少的一些数使数组变得不美丽。
Q3. 1200
给定n,k。n头牛,每头牛有自己的力量值。设比赛过程:a[1]与a[2]pk,胜者与a[3]pk,胜者依次向后pk。
对于第k头牛,你可以与其他牛交换位置/不动,问其可以取胜场数的最大值。
------------------------独自思考分割线------------------------
-
看似简单的3个题却用了2个小时各wa2一发。本以为应该10分钟一道的,看来确实思维基础不够好,本质抓的不够快,假思路太多。
A1.
两点:1.遍历每个数找出其作为b[i]和b[n+1]贡献的最小值,其他值的次数是一定的。
2.对每个a[i]讨论2种情况,找最优解。
A2.
两点:1.发现美丽的数组总是1121211311这样,即不同于a[1]的数的连续个数只能为1.
2.考虑在数组中值为a[1]的一些连续的块(双指针处理),发现只需要删除最小的块即可。
A3.
两点:1.如果不换位置,只是为a[k]安排位置的话,答案和前缀最大值有关。
2.考虑两个方向,大于a[k]和小于a[k]的。发现都是与最左端的交换更优。
------------------------代码分割线------------------------
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;
vector<int> a(n + 1), b(n + 2);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n + 1; i++)
cin >> b[i];
auto to = [](int a, int b)
{
return abs(a - b);
};
int res = 1e18, s = 0;
for (int i = 1; i <= n; i++)
s += to(a[i], b[i]);
for (int i = 1; i <= n; i++)
{
int tres = s - to(a[i], b[i]);
int minw = b[i], maxw = b[n + 1];
if (minw > maxw)
swap(maxw, minw);
if (minw >= a[i])
tres += to(a[i], maxw);
else if (maxw <= a[i])
tres += to(a[i], minw);
else
tres += to(a[i], b[i]) + to(a[i], b[n + 1]);
res = min(res, tres);
}
cout << res + 1 << 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;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<int> cnt;
for (int i = 1; i <= n; i++)
if (a[i] == a[1])
{
int x = 1;
int j = i + 1;
for (; j <= n && a[j] == a[1]; j++)
x++;
i = j - 1;
// bug(x);
cnt.push_back(x);
}
int res = n;
for (auto v : cnt)
res = min(res, v);
for (int i = 1; i < n; i++)
if (a[i] - a[1] && a[i + 1] - a[1])
res = -1;
if (a[1] - a[n] || res == n)
res = -1;
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(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int l_s = k, l_b = k;
for (int i = n; i; i--)
if (a[i] < a[k])
l_s = i;
for (int i = 1; i <= n; i++)
if (a[i] > a[k])
{
l_b = i;
break;
}
auto grt = [&](int x)
{
int res = 0;
auto t = a;
int tk = t[k];
swap(t[x], t[k]);
int maxw = t[1];
// for (int i = 1; i <= n; i++)
// cout << t[i] << " ";
// cout << endl;
for (int i = 1; i <= n; i++)
{
maxw = max(maxw, t[i]);
if (maxw > tk)
break;
else if (i - x && i >= x - 1)
res++;
}
// bug(res);
return res;
};
int res = max({grt(k), grt(l_s), grt(l_b)});
cout << res << endl;
}
合集:
日常训练
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库