2024.12.4 周三
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.4 周三
Q1. 1000
给定01串,操作:选择l,r,将s[r]放到s[l]前:s[l]s[l+1]...s[r-1]s[r]->s[r]s[l]s[l+1]...s[r-1],代价为r-l+1/区间长度。
问最小代价将01串由小到大排序。
Q2. 1300
给定2行'<''>'组成的字符串,起点[1,1],可选4个方向走一步,然后必须根据所在字符走一步。
问是否可到达[2,m]。
Q3. 1300
给定n,m。n个人在排队,你在n+1的位置。操作:你在i,与前面的j交换位置,代价a[j]+b[j+1]+..+b[i-1]。
问最小代价使你排到前m。
Q4. 1400
给定n,k,a数组。i:1~n卡牌数字i的数量为a[i]。你可以购买k张任意数字的卡牌。
问排列后可构成1~n的排列的连续子数组的最大数量。
------------------------独自思考分割线------------------------
-
这次的4道题算是比较顺,Q2 Q3都是20分钟左右,Q4近一个小时,主要是在对2种答案的讨论上费了时间,最后发现殊途同归。
A1.
两点:1.发现最终必须000011111,必要操作就是将后面的0提到1之前。
2.发现最小代价就是对最近的0操作,操作次数就是前面1的个数。即对每个0:res+=pre_1+1。
A2.
这里发现bfs可做就直接bfs了,当然也有其他巧妙的做法。
A3.
两点:1.发现本质就是在1~m选一个a[i],中间的话选min(a[i],b[i])最优。
2.操作就是m+1n:选min(a[i],b[i]),m1枚举作为终点的位置,倒序枚举可简化当其不为终点时取min(a[i],b[i])。
A4.
4点:1.贪心构造出最多排列的方式:1234123412 且数量取决于最少数量牌的个数
2.二分找出贪心购买后最少数量,枚举一次找到最少数量牌的个数。
3.设最少数量为k,其个数为cnt,,发现答案就是n*(k-1)+1+n-cnt;
4.二分的时候可能爆long long,开int128。(重测了一次,l开1e12确实有问题,r需要开到1e13,long long也没问题)
------------------------代码分割线------------------------
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 _()
{
string s;
cin >> s;
int pre = 0, res = 0;
for (auto v : s)
if (v == '0')
{
if (pre)
res += pre + 1;
}
else
pre++;
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 = 2, m;
cin >> m;
vector<string> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] = " " + a[i];
}
vector<vector<int>> vis(n + 1, vector<int>(m + 1));
auto bfs = [&]()
{
queue<pair<int, int>> q;
vis[1][1] = 1;
q.push({1, 1});
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
while (q.size())
{
auto [x, y] = q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx < 1 || nx > 2 || ny < 1 || ny > m || vis[nx][ny])
continue;
vis[nx][ny] = 1;
// bug2(nx, ny);
if (a[nx][ny] == '<')
ny--;
else
ny++;
if (nx < 1 || nx > 2 || ny < 1 || ny > m || vis[nx][ny])
continue;
// bug2(nx, ny);
vis[nx][ny] = 1;
q.push({nx, ny});
}
}
};
bfs();
cout << (vis[n][m] ? "YES" : "NO") << 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, m;
cin >> n >> m;
vector<int> a(n + 1), b(n + 1), pre(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
{
cin >> b[i];
pre[i] = pre[i - 1] + b[i];
}
int s = 0, cnt = 0;
for (int i = m + 1; i <= n; i++)
s += min(a[i], b[i]);
int res = 1e18;
int has = 0;
for (int i = m; i; i--)
{
res = min(res, s + a[i]);
s += min(a[i], b[i]);
}
cout << res << endl;
}
A4.
#include <bits/stdc++.h>
// #define int long long //
#define int __int128
#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 _();
int re()
{
int s = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9')
s = s * 10 + ch - 48, ch = getchar();
return s * f;
}
void wr(int s)
{
if (s < 0)
putchar('-'), s = -s;
if (s > 9)
wr(s / 10);
putchar(s % 10 + 48);
}
void wr(int s, char ch) { wr(s), putchar(ch); }
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
T = re();
while (T--)
_();
return 0;
}
void _()
{
int n, k;
n = re(), k = re();
vector<int> a(n);
for (int &x : a)
x = re();
auto ok = [&](int x)
{
int res = 0;
for (auto v : a)
if (x > v)
res += x - v;
return res <= k;
};
int l = 0, r = 1e13;
while (r - l - 1)
{
int mid = l + r >> 1;
if (ok(mid))
l = mid;
else
r = mid;
}
int kk = k;
int cnt = 0;
for (auto v : a)
if (l >= v)
kk -= l - v, cnt++;
cnt -= kk;
// bug2(l, cnt);
int res = n * (l - 1) + 1 + n - cnt;
// if (l * n == n + k)
// bug(1);
// res = n * (l - 1) + 1;
// if (!k)
// res = n * l - n - 1;
wr(res, '\n');
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!