2025.1.20——1300

news/2025/1/21 22:37:29/文章来源:https://www.cnblogs.com/jkkk/p/18684614

2025.1.20——1300


A 1300

You are given a binary string \(s\). A binary string is a string consisting of characters 0 and/or 1.

You can perform the following operation on \(s\) any number of times (even zero):

  • choose an integer \(i\) such that \(1 \le i \le |s|\), then erase the character \(s_i\).

You have to make \(s\) alternating, i. e. after you perform the operations, every two adjacent characters in \(s\) should be different.

Your goal is to calculate two values:

  • the minimum number of operations required to make \(s\) alternating;
  • the number of different shortest sequences of operations that make \(s\) alternating. Two sequences of operations are different if in at least one operation, the chosen integer \(i\) is different in these two sequences.

Input

The first line contains one integer \(t\) (\(1 \le t \le 10^4\)) — the number of test cases.

Each test case consists of one line containing the string \(s\) (\(1 \le |s| \le 2 \cdot 10^5\)). The string \(s\) consists of characters 0 and/or 1 only.

Additional constraint on the input:

  • the total length of strings \(s\) over all test cases does not exceed \(2 \cdot 10^5\).

B 1300

You are given two integers \(n\) and \(k\). You are also given an array of integers \(a_1, a_2, \ldots, a_n\) of size \(n\). It is known that for all \(1 \leq i \leq n\), \(1 \leq a_i \leq k\).

Define a two-dimensional array \(b\) of size \(n \times n\) as follows: \(b_{i, j} = \min(a_i, a_j)\). Represent array \(b\) as a square, where the upper left cell is \(b_{1, 1}\), rows are numbered from top to bottom from \(1\) to \(n\), and columns are numbered from left to right from \(1\) to \(n\). Let the color of a cell be the number written in it (for a cell with coordinates \((i, j)\), this is \(b_{i, j}\)).

For each color from \(1\) to \(k\), find the smallest rectangle in the array \(b\) containing all cells of this color. Output the sum of width and height of this rectangle.
Input

The first line contains a single integer \(t\) (\(1 \leq t \leq 10^4\)) — the number of test cases. Then follows the description of the test cases.

The first line of each test case contains two integers \(n\) and \(k\) (\(1 \leq n, k \leq 10^5\)) — the size of array \(a\) and the number of colors.

The second line of each test case contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(1 \leq a_i \leq k\)) — the array \(a\).

It is guaranteed that the sum of the values of \(n\) and \(k\) over all test cases does not exceed \(10^5\).


C 1300

There is an empty matrix \(M\) of size \(n\times m\).

Zhongkao examination is over, and Daniel would like to do some puzzle games. He is going to fill in the matrix \(M\) using permutations of length \(m\). That is, each row of \(M\) must be a permutation of length \(m^\dagger\).

Define the value of the \(i\)-th column in \(M\) as \(v_i=\operatorname{MEX}(M_{1,i},M_{2,i},\ldots,M_{n,i})^\ddagger\). Since Daniel likes diversity, the beauty of \(M\) is \(s=\operatorname{MEX}(v_1,v_2,\cdots,v_m)\).

You have to help Daniel fill in the matrix \(M\) and maximize its beauty.

\(^\dagger\) A permutation of length \(m\) is an array consisting of \(m\) distinct integers from \(0\) to \(m-1\) in arbitrary order. For example, \([1,2,0,4,3]\) is a permutation, but \([0,1,1]\) is not a permutation (\(1\) appears twice in the array), and \([0,1,3]\) is also not a permutation (\(m-1=2\) but there is \(3\) in the array).

\(^\ddagger\) The \(\operatorname{MEX}\) of an array is the smallest non-negative integer that does not belong to the array. For example, \(\operatorname{MEX}(2,2,1)=0\) because \(0\) does not belong to the array, and \(\operatorname{MEX}(0,3,1,2)=4\) because \(0\), \(1\), \(2\) and \(3\) appear in the array, but \(4\) does not.
Input

The first line of input contains a single integer \(t\) (\(1\le t\le 1000\)) — the number of test cases. The description of test cases follows.

The only line of each test case contains two integers \(n\) and \(m\) (\(1\le n,m\le 2\cdot 10^5\)) — the size of the matrix.

It is guaranteed that the sum of \(n\cdot m\) over all test cases does not exceed \(2\cdot 10^5\).


D 1300

This is an interactive problem!

salyg1n gave Alice a set \(S\) of \(n\) distinct integers \(s_1, s_2, \ldots, s_n\) (\(0 \leq s_i \leq 10^9\)). Alice decided to play a game with this set against Bob. The rules of the game are as follows:

  • Players take turns, with Alice going first.

  • In one move, Alice adds one number \(x\) (\(0 \leq x \leq 10^9\)) to the set \(S\). The set \(S\) must not contain the number \(x\) at the time of the move.

  • In one move, Bob removes one number \(y\) from the set \(S\). The set \(S\) must contain the number \(y\) at the time of the move. Additionally, the number \(y\) must be strictly smaller than the last number added by Alice.

  • The game ends when Bob cannot make a move or after \(2 \cdot n + 1\) moves (in which case Alice's move will be the last one).

  • The result of the game is \(\operatorname{MEX}\dagger(S)\) (\(S\) at the end of the game).

  • Alice aims to maximize the result, while Bob aims to minimize it.

Let \(R\) be the result when both players play optimally. In this problem, you play as Alice against the jury program playing as Bob. Your task is to implement a strategy for Alice such that the result of the game is always at least \(R\).

\(\dagger\) \(\operatorname{MEX}\) of a set of integers \(c_1, c_2, \ldots, c_k\) is defined as the smallest non-negative integer \(x\) which does not occur in the set \(c\). For example, \(\operatorname{MEX}(\{0, 1, 2, 4\})\) \(=\) \(3\).


E 1300

Given two arrays \(a\) and \(b\), both of length \(n\). Elements of both arrays indexed from \(1\) to \(n\). You are constructing a directed graph, where edge from \(u\) to \(v\) (\(u\neq v\)) exists if \(a_u-a_v \ge b_u-b_v\).

A vertex \(V\) is called strong if there exists a path from \(V\) to all other vertices.

A path in a directed graph is a chain of several vertices, connected by edges, such that moving from the vertex \(u\), along the directions of the edges, the vertex \(v\) can be reached.

Your task is to find all strong vertices.

For example, if \(a=[3,1,2,4]\) and \(b=[4,3,2,1]\), the graph will look like this:

The graph has only one strong vertex with number \(4\)
Input

The first line contains an integer \(t\) (\(1\le t\le 10^4\)) — the number of test cases.

The first line of each test case contains an integer \(n\) (\(2 \le n \le 2\cdot 10^5\)) — the length of \(a\) and \(b\).

The second line of each test case contains \(n\) integers \(a_1,a_2 \dots a_n\) (\(-10^9 \le a_i \le 10^9\)) — the array \(a\).

The third line of each test case contains \(n\) integers \(b_1,b_2 \dots b_n\) (\(-10^9 \le b_i \le 10^9\)) — the array \(b\).

It is guaranteed that the sum of \(n\) for all test cases does not exceed \(2\cdot 10^5\).


------------------------思考------------------------

  • 方案数/组合数学+发现结论/优化+MEX构造+交互博弈+guess。


A

  1. 难点在计算方案数,抽象了半天发现通过模拟可以得出计算方法。

B

  1. 模拟一下发现结论:本质是对 1~k 找到两侧边界开始大于其的第一个位置。
  2. 前缀维护最大值,二分可以快速回答。 但是考虑 1~k 单调性询问,发现可以双指针解决。

C

  1. 构造方式比较好想,再计算即可。

D

  1. 交互。模拟博弈过程,从答案值域和小数据下界入手。发现结论。

E

  1. 第一眼从样例猜出了答案。细想证明确实比较巧妙。

------------------------代码------------------------

A

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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;
}constexpr int mod = 998244353;
void _()
{string s;cin >> s;int n = s.size();s = " " + s;vector<int> len;for (int i = 1; i <= n; i++){int j = i;for (; j <= n && s[j] == s[i]; j++) // j停在的位置为第一个不合法的地方;len.push_back(j - i);i = j - 1;}auto get = [](int len){int ans = 1;for (int i = 1; i <= len; i++)ans = ans * i % mod;return ans;};int res = 0, f = 1, t = 0;for (auto len : len)res += len - 1, f = f * len % mod, t += len - 1;f = f * get(t) % mod;cout << res << ' ' << f;el;
}

B

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                     \for (int i = ST; i < VEC.size(); i++) \cout << VEC[i] << ' ';            \el;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, k;cin >> n >> k;vector<int> a(n + 1);vector<int> color(k + 1);for (int i = 1; i <= n; i++){int x;cin >> x;a[i] = x;color[x] = 1;}int f = 1, g = n;for (int i = 1; i <= k; i++){if (!color[i]){cout << 0 << ' ';continue;}int l = n;for (;; f++)if (a[f] >= i)break;;for (;; g--)if (a[g] >= i)break;;// bug3(i, f, g);cout << (g - f + 1 << 1) << ' ';}el;
}

C

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                         \{                                         \for (int I = ST; I < VEC.size(); I++) \cout << VEC[I] << ' ';            \el;                                   \}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;cin >> n >> m;vector<vector<int>> f(n + 1, vector<int>(m + 1));for (int j = 1; j <= m; j++)f[1][j] = j - 1;for (int i = 2; i <= min(n, m - 1); i++){f[i][1] = f[i - 1][m];for (int j = 2; j <= m; j++)f[i][j] = f[i - 1][j - 1];}for (int i = m; i <= n; i++)for (int j = 1; j <= m; j++)f[i][j] = f[i - 1][j];auto MEX = [](vector<int> a){sort(a.begin(), a.end());a.erase(unique(a.begin(), a.end()), a.end());for (int i = 0; i < a.size(); i++)if (a[i] - i)return i;return a.back() + 1;};vector<int> t;for (int j = 1; j <= m; j++){vector<int> a;for (int i = 1; i <= n; i++)a.push_back(f[i][j]);t.push_back(MEX(a));}// bugv(t, 0);cout << MEX(t);el;for (int i = 1; i <= n; i++)bugv(f[i], 1);
}

D

#include <bits/stdc++.h>
#define int long long //
// #define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                         \{                                         \for (int I = ST; I < VEC.size(); I++) \cout << VEC[I] << ' ';            \el;                                   \}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;map<int, bool> has;for (int i = 0; i < n; i++){int x;cin >> x;has[x] = 1;}auto f = [](int x){cout << x << endl;cin >> x;return x;};if (!has[0]){f(0);return;}int ans = 0;for (;; ans++)if (!has[ans])break;int x = f(ans);while (~x)x = f(x);
}

E

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // attention: interactive/debug
#define el cout << endl
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
#define bugv(VEC, ST)                         \{                                         \for (int I = ST; I < VEC.size(); I++) \cout << VEC[I] << ' ';            \el;                                   \}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> f(n);for (int &x : f)cin >> x;int mx = -1e10;for (int i = 0; i < n; i++){int x;cin >> x;f[i] -= x;mx = max(mx, f[i]);}int cnt = 0;vector<int> res;for (int i = 0; i < n; i++)if (f[i] == mx)cnt++, res.push_back(i + 1);cout << cnt;el;bugv(res, 0);
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/873022.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

制作docker 镜像上传到docker hub仓库

注册docker hub账号 https://hub.docker.com/ 参照此篇:https://www.cnblogs.com/yjlch1016/p/8998479.htmldocker hub上创建仓库https://hub.docker.com/repositories 本地制作镜像并上传在本地登陆 docker hub 帐号docker login将容器commit 成镜像,可以先用docker …

虚拟现实国标解读系列(一)帧率

大家好,我是ij(我的网名),中文名叫林志宏。 遵循我一贯的年底必摸鱼的习惯,我打算开始摸鱼来水一些文章,安慰下自己过去的一年。 有关注过我,听我吹过牛的都知道,我在几年前,也不知道几年前, 反正long long ago,我参与起草过一份牛逼的测试标准,国标GB/T 38258《虚…

【Linux网络】深入理解linux内核网络性能优化

一、网络请求优化 1.1 减少不必要的网络IO 在系统设计与开发过程中,应尽量避免不必要的网络I/O操作,尤其是在可以通过本地进程或内存内完成的场景下,避免使用网络通信来实现。网络虽然是现代分布式系统中的核心组件,能够连接不同模块、简化开发流程,并支持大规模系统的构建…

【Java开发】简化Maven项目依赖:优雅去除未使用Jar包

一、为什么要做这件事? 自从我踏入职场,便历经了技术革新的数次浪潮。从最初的.Net Framework、Winform、WPF,到Asp.Net MVC、Asp.Net MVC WebApi,再到Asp.Net Core 2.x的广泛应用,我始终深耕于.net领域。 然而,随着技术的不断演进,我逐渐发现.net相关的工作机会变得稀少…

《操作系统真相还原》实验记录2.7——生产者与消费者问题

本节实现内容如下: ① 环形缓存区的结构体创建; ② 环形键盘缓冲区的创建; ③ 生产者消费者问题剖析;一、生产者与消费者问题简述我们知道,在计算机中可以并行多个线程,当它们之间相互合作时,必然会存在共享资源的问题,这是通过“线程同步”来解决的,而诠释“线程同步…

CTF-web第一步!

本次的题比较简单,适合我这种入门学者。CTF菜狗杯的web2 c0me_t0_s1gn。进入靶场打开F12会得到前一半。在控制台复制函数give_flag()会得到另一半。 这样就完成了。

P1183 多边形的面积-向量的用法

原题链接 https://www.luogu.com.cn/problem/P1183 题目描述 给出一个没有缺口的简单多边形,它的边是垂直或者水平的,要求计算多边形的面积。 xOy 的笛卡尔平面上,它所有的边都平行于两条坐标轴之一。然后按逆时针方向给出各顶点的坐标值。所有的坐标值都是整数,因此多边形…

蓄水池漂浮物识别摄像机

蓄水池漂浮物识别摄像机具有高效的图像识别功能。通过高清晰度的摄像头捕捉到蓄水池表面的图像,并通过人工智能技术进行快速准确的漂浮物识别。这种摄像机可以自动检测出池面上的漂浮物,并生成相应报警信息。该摄像机支持多种智能算法分析,并通过智能算法对数据进行综合分析…

行为智能识别摄像机

行为智能识别摄像机通过结合人工智能技术和监控技术,实现了对各种行为动作的自动识别和分析,在提高安全性、减少事故发生率方面具有重要意义。随着科技的不断进步和应用范围的扩大,相信这种先进设备将会在更多领域得到广泛应用。行为智能识别摄像机是一种结合了人工智能技术…

AI人数智能统计监测摄像头

AI人数智能统计监测摄像头具有高效的图像识别功能。通过先进的图像处理算法,可以快速准确地识别出场景中的人群,并进行实时统计。无论是密集的人流场所还是较为稀疏的区域,这种摄像头都能够精准地进行人数统计,为管理者提供重要参考信息。AI人数智能统计监测摄像头具有实时…

Android 中的卡顿丢帧原因概述 - 方法论

Android 手机使用中的卡顿问题 , 一般来说手机厂商和 App 开发商都会非常重视 , 所以不管是手机厂商还是 App 开发者 , 都会对卡顿问题非常重视 , 内部一般也会有专门的基础组或者优化组来进行优化 . 目前市面上有一些非常棒的第三方性能监控工具 , 比如腾讯的 Matrix ; 手机厂…

JavaScript的常用库 —— jQuery

利用JS去操控HTML和CSS,常用库之jQuery ฅʕ•̫͡•ʔฅjQuery用来更加方便地去控制前端的HTML标签和CSS属性。使用方式:1. 直接在<head>元素中添加: <script src="https://cdn.acwing.com/static/jquery/js/jquery-3.3.1.min.js"></script> 2…