[Codeforces ROUND 991 Div.3] 1205
A. Line Breaks
time limit per test: 1 second
memory limit per test: 256 megabytes
题解
题目
Kostya has a text
Kostya must choose a number
Since space on the second strip is very valuable, Kostya asks you to choose the maximum possible number
科斯佳(Kostya)有一段文本
科斯佳必须选择一个数字
由于第二张纸条上的空间非常宝贵,科斯佳请你选择最大可能的数字
样例
INPUT
The first line contains an integer
The first line of each test case contains two integers
The next
OUTPUT
For each test case, output the maximum number of words
示例
1 | 5 |
1 | 1 |
B. Transfusion
time limit per test: 2 seconds
memory limit per test: 256 megabytes
题解
题目
You are given an array
- Decrease
by , then increase by . - Decrease
by , then increase by .
After each operation, all the values must be non-negative. Can you make all the elements equal after any number of operations?
给定一个长度为
- 将
减 1,然后将 加 1。 - 将
减 1,然后将 加 1。
在每次操作之后,所有的值都必须是非负的。经过任意次数的操作后,你能否使所有元素都相等呢?
样例
INPUT
First line of input consists of one integer
First line of each test case consists of one integer
Second line of each test case consists of
It is guaranteed that the sum of
OUTPUT
For each test case, print "YES"
without quotation marks if it is possible to make all the elements equal after any number of operations; otherwise, print "NO"
without quotation marks.
You can print answers in any register: "yes"
, "YeS"
, "nO"
— will also be considered correct.
示例
1 | 8 |
1 | YES |
C. Uninteresting Number
time limit per test: 2 seconds
memory limit per test: 256 megabytes
题解
题目
You are given a number
You can perform the following operation any number of times: choose one of its digits, square it, and replace the original digit with the result. The result must be a digit (that is, if you choose the digit
Is it possible to obtain a number that is divisible by
给定一个长度不超过
你可以任意多次执行以下操作:选择它的其中一位数字,将其平方,然后用所得结果替换原来的数字。结果必须是一位数字(也就是说,如果你选择数字
通过这些操作,是否有可能得到一个能被 9 整除的数字呢?
样例
INPUT
The first line contains an integer
The only line of each test case contains the number
It is guaranteed that the sum of the lengths of the numbers across all test cases does not exceed
OUTPUT
For each test case, output "YES"
if it is possible to obtain a number divisible by "NO"
otherwise.
You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs"
, "yes"
, "Yes"
, and "YES"
will be accepted as a positive answer.
示例
1 | 9 |
1 | NO |
D. Digital string maximization
time limit per test: 2 seconds
memory limit per test: 256 megabytes
题解
题目
You are given a string
For example, in one operation from the string
Find the lexicographically maximum string you can obtain after any number of operations.
给定一个字符串
例如,对字符串
求出经过任意次数的操作后,你所能得到的按字典序最大的字符串。
样例
INPUT
The first line of the input consists of an integer
Each test case consists of a single line consisting of a digital string
It is guaranteed that the sum of
OUTPUT
For each test case, print the answer on a separate line.
示例
1 | 6 |
1 | 81 |
示例解释
In the first example, the following sequence of operations is suitable: 19 → 81.
In the second example, the following sequence of operations is suitable: 1709 → 1780 → 6180 → 6710.
In the fourth example, the following sequence of operations is suitable: 51476 → 53176 → 53616 → 53651 → 55351 → 55431.
在第一个例子中,以下操作顺序是合适的: 19 → 81.
在第二个例子中,以下运算顺序是合适的: 1709 → 1780 → 6180 → 6710.
在第四个例子中,适合采用以下运算顺序: 51476 → 53176 → 53616 → 53651 → 55351 → 55431.
E. Three Strings
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
题解
题目
You are given three strings:
- At each step, either string
or string was randomly chosen, and the first character of the chosen string was removed from it and appended to the end of string , until one of the strings ran out. After that, the remaining characters of the non-empty string were added to the end of . - Then, a certain number of characters in string
were randomly changed.
For example, from the strings a=abra and b=cada, without character replacements, the strings caabdraa, abracada, acadabra could be obtained.
Find the minimum number of characters that could have been changed in string
给定三个字符串:
- 在每一步中,随机选择字符串
或者字符串 ,将所选字符串的第一个字符从该字符串中移除,并添加到字符串 的末尾,直到其中一个字符串中的字符被取完为止。之后,将非空字符串中剩余的字符添加到 的末尾。 - 然后,字符串
中的若干字符被随机更改了。
例如,对于字符串 abra 和 cada,在不进行字符替换的情况下,可能会得到诸如 caabdraa 、abracada、acadabra 这样的字符串。
求出字符串
样例
INPUT
The first line of the input contains a single integer
The first line of each test case contains one string of lowercase Latin letters
The second line of each test case contains one string of lowercase Latin letters
The third line of each test case contains one string of lowercase Latin letters
It is guaranteed that the sum of
OUTPUT
For each test case, output a single integer — the minimum number of characters that could have been changed in string
示例
1 | 7 |
1 | 1 |
F. Maximum modulo equality
time limit per test: 5 seconds
memory limit per test: 256 megabytes
题解
题目
You are given an array
For each query, find the maximum possible
给定一个长度为
对于每个查询,找出最大可能的
样例
INPUT
The first line contains a single integer
The first line of each test case contains two integers
The second line of each test case contains
In the following
It is guaranteed that the sum of
OUTPUT
For each query, output the maximum value
示例
1 | 3 |
1 | 3 1 4 1 0 |
示例解释
In the first query of the first sample,
In the third query of the first sample,
在第一个示例的第一个查询中,
在第一个示例的第三个查询中,
G. Tree Destruction
time limit per test: 2 seconds
memory limit per test: 256 megabytes
题解
题目
Given a tree∗ with
Your task is to find the maximum number of connected components† that can be formed after removing the path from the tree.
∗ A tree is a connected graph without cycles.
† A connected component is a set of vertices such that there is a path along the edges from any vertex to any other vertex in the set (and it is not possible to reach vertices not belonging to this set)
给定一棵有
你的任务是找出从这棵树中移除该路径后,所能形成的连通分量†的最大数量。
∗ 树是一种无环的连通图。
† 连通分量是一组顶点的集合,在这个集合中,从任意一个顶点沿着边都能到达集合内的任意其他顶点(并且无法到达不属于这个集合的顶点)。
样例
INPUT
The first line of the input contains one integer
The first line of each test case contains one integer
The next n−1 lines contain two integers u and
It is guaranteed that the sum of
OUTPUT
For each test case, output one integer — the maximum number of connected components that can be achieved using the described operation.
示例
1 | 6 |
1 | 1 |
- 标题: [Codeforces ROUND 991 Div.3] 1205
- 作者: CatIsNotFound
- 创建于 : 2024-12-06 12:07:26
- 更新于 : 2024-12-06 12:07:26
- 链接: https://catisnotfound.github.io/2024/12/CF-R991-D3/
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。