2025.1.15——1200
Q1. 1200
简单来说就是给定3个数组,每个数组选择一个数,三者下标不同,问三者和的最大值。
Winter holidays are coming up. They are going to last for n n n days.
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 i i i-th day, exactly a i a_i ai friends will join him for skiing, b i b_i bi friends will join him for a movie and c i c_i ci friends will join him for board games.
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
x
,
y
,
z
x, y, z
x,y,z in such a way that the total number of friends to join him for the activities (
a
x
+
b
y
+
c
z
a_x + b_y + c_z
ax+by+cz) is maximized.
Input
The first line of each testcase contains a single integer n n n ( 3 ≤ n ≤ 1 0 5 3 \le n \le 10^5 3≤n≤105) — the duration of the winter holidays in days.
The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 8 1 \le a_i \le 10^8 1≤ai≤108) — the number of friends that will join Monocarp for skiing on the i i i-th day.
The third line contains n n n integers b 1 , b 2 , … , b n b_1, b_2, \dots, b_n b1,b2,…,bn ( 1 ≤ b i ≤ 1 0 8 1 \le b_i \le 10^8 1≤bi≤108) — the number of friends that will join Monocarp for a movie on the i i i-th day.
The fourth line contains n n n integers c 1 , c 2 , … , c n c_1, c_2, \dots, c_n c1,c2,…,cn ( 1 ≤ c i ≤ 1 0 8 1 \le c_i \le 10^8 1≤ci≤108) — the number of friends that will join Monocarp for board games on the i i i-th day.
Q2. 1200
You are given an array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an of distinct positive integers. You have to do the following operation exactly once:
- choose a positive integer k k k;
- for each i i i from 1 1 1 to n n n, replace a i a_i ai with a i mod k † a_i \text{ mod } k^\dagger ai mod k†.
Find a value of k k k such that 1 ≤ k ≤ 1 0 18 1 \leq k \leq 10^{18} 1≤k≤1018 and the array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an contains exactly 2 2 2 distinct values at the end of the operation. It can be shown that, under the constraints of the problem, at least one such k k k always exists. If there are multiple solutions, you can print any of them.
† ^\dagger † a mod b a \text{ mod } b a mod b denotes the remainder after dividing a a a by b b b. For example:
- 7 mod 3 = 1 7 \text{ mod } 3=1 7 mod 3=1 since 7 = 3 ⋅ 2 + 1 7 = 3 \cdot 2 + 1 7=3⋅2+1
- 15 mod 4 = 3 15 \text{ mod } 4=3 15 mod 4=3 since 15 = 4 ⋅ 3 + 3 15 = 4 \cdot 3 + 3 15=4⋅3+3
- 21 mod 1 = 0 21 \text{ mod } 1=0 21 mod 1=0 since 21 = 21 ⋅ 1 + 0 21 = 21 \cdot 1 + 0 21=21⋅1+0
Input
The first line of each test case contains a single integer n n n ( 2 ≤ n ≤ 100 2 \le n \le 100 2≤n≤100) — the length of the array a a a.
The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 17 1 \le a_i \le 10^{17} 1≤ai≤1017) — the initial state of the array. It is guaranteed that all the a i a_i ai are distinct.
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 M M M with n n n rows and n n n columns of non-negative integers, and to open the lock, you need to find an array a a a of n n n elements such that:
- 0 ≤ a i < 2 30 0 \le a_i < 2^{30} 0≤ai<230, and
- M i , j = a i ∣ a j M_{i,j} = a_i | a_j Mi,j=ai∣aj for all i ≠ j i \neq j i=j, 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 n n n by n n n, filled with lowercase Latin letters. The value of n n n is even.
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 9 0 ∘ 90^\circ 90∘ clockwise once.
Here is an example of rotating a matrix by 9 0 ∘ 90^\circ 90∘:
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 n + 1 n+1 n+1 slots numbered from 1 1 1 to n + 1 n+1 n+1 from left to right. The n + 1 n+1 n+1 slots are going to be filled with an array of non-negative integers [ a 1 , a 2 , a 3 , … , a n + 1 ] [a_1,a_2,a_3,\ldots,a_{n+1}] [a1,a2,a3,…,an+1]. Chaneka, as the player, must assign a n + 1 a_{n+1} an+1 with an integer between 0 0 0 and m m m inclusive. Then, for each i i i from n n n to 1 1 1, the value of a i a_i ai will be equal to the remainder of dividing a i + 1 a_{i+1} ai+1 (the adjacent value to the right) by i i i. In other words, a i = a i + 1 m o d i a_i = a_{i + 1} \bmod i ai=ai+1modi.
Chaneka wants it such that after every slot is assigned with an integer, there are exactly
k
k
k distinct values in the entire screen (among all
n
+
1
n+1
n+1 slots). How many valid ways are there for assigning a non-negative integer into slot
n
+
1
n+1
n+1?
Input
The only line of each test case contains three integers n n n, m m m, and k k k ( 1 ≤ n ≤ 1 0 9 1 \leq n \leq 10^9 1≤n≤109; 0 ≤ m ≤ 1 0 9 0 \leq m \leq 10^9 0≤m≤109; 1 ≤ k ≤ n + 1 1 \leq k \leq n+1 1≤k≤n+1) — there are n + 1 n+1 n+1 slots, the integer assigned in slot n + 1 n+1 n+1 must not be bigger than m m m, and there should be exactly k k k distinct values.
------------------------独自思考分割线------------------------
A1
- 卡了好久在想优化,感觉优化很麻烦。其实方向错了。
- 发现结论:可缩小范围,每个数组选择的范围只有三个数。
- 据说还有dp解法。
A2.
- 充分性:在所有数不相同条件下,在二进制之下,由低位到高位必然会存在两种值。
A3
- 位运算局部到整体:构造每一位,若 M M M 为 0 0 0, a i a_i ai a j a_j aj 必为 0 0 0,否则使 a i a_i ai a j a_j aj 为 1 1 1 。
- 是道神秘题,充分必要性我现在不能证明。
点击链接去洛谷吧
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;
}
标签:le,2025.1,int,1200,ai,15,define,mx,mod From: https://blog.csdn.net/2302_79354434/article/details/145177203