首页 > 其他分享 >2025.1.15——1200

2025.1.15——1200

时间:2025-01-16 12:30:46浏览次数:3  
标签:le 2025.1 int 1200 ai 15 define mx mod

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+1​modi.

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.


------------------------独自思考分割线------------------------

  • 发现结论+发现充分性结论/二进制/取模+位运算/神秘题+发现结论/推坐标+数论/模拟结论。前3题被卡了,值得回味。


A1

  1. 卡了好久在想优化,感觉优化很麻烦。其实方向错了。
  2. 发现结论:可缩小范围,每个数组选择的范围只有三个数。
  3. 据说还有dp解法。

A2.

  1. 充分性:在所有数不相同条件下,在二进制之下,由低位到高位必然会存在两种值。

A3

  1. 位运算局部到整体:构造每一位,若 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 。
  2. 是道神秘题,充分必要性我现在不能证明。 点击链接去洛谷吧

A4

  1. 发现结论:对应的四个位置绑定,都要变相同取最大值。
  2. 推出动态坐标即可。

A5

  1. 数论一下或模拟发现结论。

------------------------代码分割线------------------------

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

相关文章

  • 【2025-01-15】成人孤独
    20:00我们的弱点也许会给我们提供一种出乎意料的助力。                                                 ——威廉·詹姆斯何太昨晚躺在床上刷着淘宝跟起说,现在买东西......
  • 《CPython Internals》阅读笔记:p152-p176
    《CPythonInternals》学习第10天,p152-p176总结,总计25页。一、技术总结1.addinganitemtoalistmy_list=[]my_list.append(obj)上面的代码涉及两个指令:LOAD_FAST,LIST_APPEND。整章看下来这有这点算是可以记的了,其它的只感觉作者在零零碎碎的罗列内容。二、英语......
  • 2025年1月15日
    调整今天总结了一下昨天的那种通透的感觉目标清晰团队氛围的带动对环境的熟悉个人的极度感知团队领导的刻意安排(他给你留了一个施展你才能的位置你进入状态很自然现在才后知后觉)你自身不懈的努力接下来怎么破你自己的局呢先是客观事实的分析、然后是几个核心模......
  • 151. 反转字符串中的单词
    题目不会做,老老实实看卡哥思路,这里面讲的很详细,有很多值得学习揣摩的东西。在把空格处理好后,先反转整体,再反转其中的单词的方法,很值得学习。即使用整体反转+局部反转就可以实现反转单词顺序的目的跟着卡哥代码敲了一遍:classSolution{public:voidreverse(string&s,i......
  • Diary - 2025.01.15
    其实是pkuwc2024的东西。Day0坐飞机坐飞机,嘟嘟嘟。大飞机!!!!!!!!我觉得最厉害的是这个飞机有3D地图啊,太帅了!!!但是比较悲伤的是我直到要到了才知道,前面都在看B站缓存的视频......
  • 1.15 SQL语句练习(增删改查)
    1.DML(增删改)增给指定列添加数据INSERTINTO表名(列名1,列名2,…)VALUES(值1,值2,…);给全部列添加数据INSERTINTO表名VALUES(值1,值2,…);批量添加数据INSERTINTO表名(列名1,列名2,…)VALUES(值1,值2,…),(值1,值2,…),(值1,值2,…)…;INSERTINTO表名VALUES(......
  • 2025.1.15 html基础
    学习了html的基础知识,包括:n越大,字体越小换行标签表示一个完整的段落水平线标签 链接:内容例如:<!--a页面-->这是A页面。<!--b页面-->这是B页面。在浏览器中点击“这是A页面”,会跳转到b页面。......
  • 十分钟写作Day3 1.15
    正文那真是令人心潮澎湃的一个时刻,听着墙上的钟表“哒,哒,哒……”地走着,我的内心不禁“扑通,扑通,扑通……”般跳动起来。我额头上出现的词语会是什么呢?也许是“外向”,毕竟我是妥妥的“E”人也许是“聪慧”,毕竟我这么聪明,从小就智商高也许是“合群”,毕竟我的交友圈极为广......
  • 逐笔成交逐笔委托Level2高频数据下载和分析:20250115
    逐笔成交逐笔委托下载链接:https://pan.baidu.com/s/1uRCmUTFoUZShauQ0gJYFiw?pwd=f837提取码:f837--------------------Level2逐笔成交逐笔委托数据分享下载 采用Level2逐笔成交与逐笔委托的详细记录,这种毫秒级别的数据能揭露众多关键信息,如庄家意图、虚假交易,使所有......
  • Codeforces 1536B Prinzessin der Verurteilung 题解 [ 紫 ] [ 后缀自动机 ] [ 动态规
    PrinzessinderVerurteilung:最短未出现字符串的板子。思路考虑在SAM上dp,定义\(dp_i\)表示从\(i\)节点走到NULL节点所花费的最少步数。显然我们建出反图,跑DAG上dp即可。转移如下:\[dp_i=1+\min_{j=1}^{|v_i|}dp_{v_{i,j}}\]输出方案的话记录下每个dp值的先驱,最......