2024.12.18 周三
2024.12.18 周三
Q1. 1000
You have an array of zeros
You can perform two types of operations on it:
- Choose an index
such that and , and assign to ; - Choose a pair of indices
and such that , , , , and assign to for all .
What is the minimum number of operations of the first type needed to make all elements of the array equal to one?
Q2. 1000
Fedya is playing a new game called "The Legend of Link", in which one of the character's abilities is to combine two materials into one weapon. Each material has its own strength, which can be represented by a positive integer
Formally, let the first material have strength
Fedya has an unlimited supply of materials with all possible strengths from
An integer
Q3. 1000
You are given two arrays
You will merge
Q4. 1000
LuoTianyi gave an array
This means that we consider
Help her find the maximal possible value, you don't need to reconstruct the table itself.
------------------------独自思考分割线------------------------
-
用时:20 20 40(-2) 14 总:1h34min 虽然都不难,但都不是一眼,需要证明/发现。
A1.
- 贪心构造,首先两端必须有,自左向右贪心找中间点,发现其坐标最大为
。
A2.
- 模拟数位发现,在等长度情况下,以第一个不同点为分界线,前面每一位最大贡献就是
,后面每一位最大贡献就是 。 - 本质就是考虑每一位数的取值范围,相同前缀下
只能取 ,否则可取 。
A3.
- 将连续相同的数看成一块,根据构造方案,同一数组的相同数的2块不可能合并,不同数组则一定可以合并。
- 那答案显而易见,记录每个数所在块的最大值,答案就是每个数在两数组块的和的最大值。
- 写的时候直接枚举
数组去另一数组找另外的数wa2发,扒数据也没找到原因,果然wa了只有思路/代码有问题,这种情况就是没有考虑一个数没有在两个数组都存在的情况。
A4.
- 贪心构造,将极差最大的几个数放在左上角,
到 一定可以构造出 ,还剩下第一行和第一列。 - 考虑将
放 放 ,同时最小值也可放左上角,维护最大值、次大值、最小值、次小值。同时考虑行列,设置函数进行4次计算即可。显然没有方案更优。
------------------------代码分割线------------------------
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;
int res = 2;
int st = 4;
for (; st < n; st = st + 1 << 1)
res++;
if (n == 1)
res = 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(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
string a, b;
cin >> a >> b;
int n = a.size(), m = b.size();
string t(max(n, m) - min(n, m), '0');
if (n < m)
a = t + a;
else
b = t + b;
n = max(n, m);
int f = 0, res = 0;
for (int i = 0; i < n; i++)
{
if (!f && a[i] == b[i])
continue;
res += f ? 9 : abs(b[i] - a[i]);
if (a[i] - b[i])
f = 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;
cin >> n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
map<int, int> la, lb;
auto get = [&](vector<int> &a, map<int, int> &la)
{
for (int i = 1; i <= n; i++)
{
int j = i;
for (; j <= n && a[j] == a[i]; j++)
;
la[a[i]] = max(la[a[i]], j - i);
i = j - 1;
}
};
get(a, la);
get(b, lb);
int res = 0;
for (int i = 1; i <= n << 1; i++)
res = max(res, la[i] + lb[i]);
// for (auto [x, v] : la)
// res = max(res, v + lb[x]);
cout << res << endl;
}
A4.
#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 * m);
for (int &x : a)
cin >> x;
sort(a.begin(), a.end());
int max1 = a.back(), max2 = a[a.size() - 2];
int min1 = a[0], min2 = a[1];
int res = (n - 1) * (m - 1) * (max1 - min1);
auto cal = [&](int a, int b, int c)
{
return (n - 1) * abs(b - a) + (m - 1) * abs(c - a);
};
vector<int> t{cal(max1, min1, min2), cal(max1, min2, min1), cal(min1, max2, max1), cal(min1, max1, max2)};
sort(t.rbegin(), t.rend());
res += t[0];
cout << res << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!