2025.1.15——1200
2025.1.15——1200
Q1. 1200
简单来说就是给定3个数组,每个数组选择一个数,三者下标不同,问三者和的最大值。
Winter holidays are coming up. They are going to last for
During the holidays, Monocarp wants to try all of these activities exactly once with his friends:
- go skiing;
- watch a movie in a cinema;
- play board games.
Monocarp knows that, on the
Monocarp also knows that he can't try more than one activity in a single day.
Thus, he asks you to help him choose three distinct days
Input
The first line of each testcase contains a single integer
The second line contains
The third line contains
The fourth line contains
Q2. 1200
You are given an array
- choose a positive integer
; - for each
from to , replace with .
Find a value of
since since since
Input
The first line of each test case contains a single integer
The second line of each test case contains
Q3. 1200
In Cyprus, the weather is pretty hot. Thus, Theofanis saw this as an opportunity to create an ice cream company.
He keeps the ice cream safe from other ice cream producers by locking it inside big storage rooms. However, he forgot the password. Luckily, the lock has a special feature for forgetful people!
It gives you a table
, and for all , where denotes the bitwise OR operation.
The lock has a bug, and sometimes it gives tables without any solutions. In that case, the ice cream will remain frozen for the rest of eternity.
Can you find an array to open the lock?
Q4. 1200
Kristina has a matrix of size
She wants to change some characters so that her matrix becomes a perfect square. A matrix is called a perfect square if it remains unchanged when rotated
Here is an example of rotating a matrix by
In one operation, Kristina can choose any cell and replace its value with the next character in the alphabet. If the character is equal to "z", its value does not change.
Find the minimum number of operations required to make the matrix a perfect square.
Q5. 1200
Chaneka, a gamer kid, invented a new gaming controller called joyboard. Interestingly, the joyboard she invented can only be used to play one game.
The joyboard has a screen containing
Chaneka wants it such that after every slot is assigned with an integer, there are exactly
Input
The only line of each test case contains three integers
------------------------独自思考分割线------------------------
-
发现结论+发现充分性结论/二进制/取模+位运算/神秘题+发现结论/推坐标+数论/模拟结论。前3题被卡了,值得回味。
A1
- 卡了好久在想优化,感觉优化很麻烦。其实方向错了。
- 发现结论:可缩小范围,每个数组选择的范围只有三个数。
- 据说还有dp解法。
A2.
- 充分性:在所有数不相同条件下,在二进制之下,由低位到高位必然会存在两种值。
A3
- 位运算局部到整体:构造每一位,若
为 , 必为 ,否则使 为 。 - 是道神秘题,充分必要性我现在不能证明。
点击链接去洛谷吧
A4
- 发现结论:对应的四个位置绑定,都要变相同取最大值。
- 推出动态坐标即可。
A5
- 数论一下或模拟发现结论。
------------------------代码分割线------------------------
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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n), b(n), c(n);
for (int &x : a)
cin >> x;
for (int &x : b)
cin >> x;
for (int &x : c)
cin >> x;
struct Node
{
int x, idx;
};
vector<Node> mx1, mx2, mx3;
auto get = [](vector<int> &a, vector<Node> &mx)
{
mx.assign(3, {-1, -1});
for (int i = 0; i < a.size(); i++)
if (a[i] > mx[0].x)
mx[2] = mx[1], mx[1] = mx[0], mx[0] = {a[i], i};
else if (a[i] > mx[1].x)
mx[2] = mx[1], mx[1] = {a[i], i};
else if (a[i] > mx[2].x)
mx[2] = {a[i], i};
};
get(a, mx1);
get(b, mx2);
get(c, mx3);
int res = 0;
for (auto [va, ida] : mx1)
for (auto [vb, idb] : mx2)
for (auto [vc, idc] : mx3)
if (ida - idb && ida - idc && idb - idc)
res = max(res, va + vb + vc);
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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n);
for (int &x : a)
cin >> x;
int bit = 0;
auto check = [&](int bit)
{
int two[2] = {};
for (auto v : a)
two[v >> bit & 1]++;
return two[0] && two[1];
};
for (;; bit++)
if (check(bit))
break;
cout << (1ll << bit + 1) << 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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<vector<int>> a(n + 1, vector<int>(n + 1));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
vector<int> res(n + 1, (1ll << 30) - 1);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
res[i] &= a[i][j], res[j] &= a[i][j];
bool f = 1;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if ((res[i] | res[j]) - a[i][j])
f = 0;
cout << (f ? "YES" : "NO") << endl;
if (f)
for (int i = 1; i <= n; i++)
cout << res[i] << ' ';
cout << 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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<string> a(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] = " " + a[i];
}
int res = 0;
auto get = [](char a, char b, char c, char d)
{
int ans = 0;
char mx = max({a, b, c, d});
ans += abs(mx - a) + abs(mx - b) + abs(mx - c) + abs(mx - d);
return ans;
};
for (int i = 1; i <= n >> 1; i++)
for (int j = 1; j <= n >> 1; j++)
res += get(a[i][j], a[n - i + 1][n - j + 1], a[n - j + 1][i], a[j][n - i + 1]);
cout << res << endl;
}
A5
#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(10);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n, m, k;
cin >> n >> m >> k;
int res = 0;
if (m > n)
res = m - n + 1 - m / n;
if (k == 1)
res = 1;
if (k == 2)
res = m - res;
if (k > 3)
res = 0;
cout << res << endl;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!