Codeforces Round #777 (Div. 2)
比赛链接
Codeforces Round #777 (Div. 2)
B. Madoka and the Elegant Gift
Madoka's father just reached 1 million subscribers on Mathub! So the website decided to send him a personalized award - The Mathhub's Bit Button!
The Bit Button is a rectangular table with rows and columns with 0 or 1 in each cell. After exploring the table Madoka found out that:
- A subrectangle is contained in a subrectangle if there's no cell contained in but not contained in .
- Two subrectangles intersect if there is a cell contained in both of them.
- A subrectangle is called black if there's no cell with value 0 inside it.
- A subrectangle is called nice if it's black and it's not contained in another black subrectangle.
- The table is called elegant if there are no two nice intersecting subrectangles.
For example, in the first illustration the red subrectangle is nice, but in the second one it's not, because it's contained in the purple subrectangle.
Help Madoka to determine whether the table is elegant.
Input
Each test contains multiple test cases. The first line contains a single integer the number of test cases. Description of the test cases follows.
The first line of each test case contains two positive integers
The next lines contain strings of length consisting of zeros and ones - the description of the table.
It is guaranteed that the sum of the values of and the sum of the values of for all test cases do not exceed 777 .
Output
For each test case print "YES" if its table is elegant or print "NO" otherwise.
You may print each letter in any case (for example, "YES", "Yes", "Yes", "yEs" will all be recognized as positive answer).
Example
input
output
Note
In the second test case the table is not elegant, because the red and the purple subrectangles are nice and intersect.
In the fourth test case the table is not elegant, because the red and the purple subrectangles are nice and intersect.
解题思路
规律
可发现交叉处的点满足四个角中仅有一个角为黑色,枚举每一个交叉点判断是否有这样的点
- 时间复杂度:
代码
C. Madoka and Childish Pranks
Madoka as a child was an extremely capricious girl, and one of her favorite pranks was drawing on her wall. According to Madoka's memories, the wall was a table of rows and columns, consisting only of zeroes and ones. The coordinate of the cell in the -th row and the -th column is .
One day she saw a picture "Mahou Shoujo Madoka Magica" and decided to draw it on her wall. Initially, the Madoka's table is a table of size filled with zeroes. Then she applies the following operation any number of times:
Madoka selects any rectangular subtable of the table and paints it in a chess coloring (the upper left corner of the subtable always has the color 0 ). Note that some cells may be colored several times. In this case, the final color of the cell is equal to the color obtained during the last repainting.
White color means 0 , black means 1 . So, for example, the table in the first picture is painted in a chess coloring, and the others are not.
For better understanding of the statement, we recommend you to read the explanation of the first test.
Help Madoka and find some sequence of no more than operations that allows you to obtain the picture she wants, or determine that this is impossible.
Input
Each test contains multiple test cases. The first line contains a single integer the number of test cases. Description of the test cases follows.
The first line of each test case contains two integers and the size of the table. Each of the following lines contains a string of length consisting only of 1 and 0 - description of the picture that Madoka wants to obtain.
Output
If it is impossible to obtain the given picture, print .
Otherwise, print in the first line a single integer - the number of operations you need to obtain the picture. Note that you do not need to minimize the number of operations.
Then for each operation (in the order of execution) print a single line containing four numbers — the coordinates of the upper-left corner and the lower-right corner of the rectangle.
Example
input
output
Note
The description of the first test case is below.
In the third test case, it is impossible to paint the desired picture.
In the fourth test case, the initial table is already the desired picture.
解题思路
思维
每次只用 或 的矩形操作即可,即对于每一列,从下往上如果 要求为黑色,则填充 ,列都填充完后,这时只剩第一行,同理填充,另外如果第一行第一列要求黑色,则显然无法满足条件
- 时间复杂度:
代码
D. Madoka and the Best School in Russia
Madoka is going to enroll in "TSUNS PTU". But she stumbled upon a difficult task during the entrance computer science exam:
- A number is called good if it is a multiple of .
- A number is called beatiful if it is good and it cannot be represented as a product of two good numbers.
Notice that a beautiful number must be good.
Given a good number , determine whether it can be represented in at least two different ways as a product of several (possibly, one) beautiful numbers. Two ways are different if the sets of numbers used are different.
Solve this problem for Madoka and help her to enroll in the best school in Russia!
Input
The first line contains a single integer - number of test cases. Below comes their description.
Each test case consists of two integers and , separated by a space . It is guaranteed that is a multiple of .
Output
For each set of input data, output "NO" if the number cannot be represented in at least two ways. Otherwise, output "YES".
You can output each letter in any case (for example, "YES", "Yes", "Yes", "YEs", "YEs" will be recognized as a positive answer).
Example
input
output
Note
In the first example, 6 can be represented as . But 3 and 1 are not a good numbers because they are not divisible by 2 , so there is only one way.
In the second example, 12 can be represented as , or . The first option is suitable. The second is- no, because 12 is not beautiful number . The third and fourth are also not suitable, because 3 is not good number.
In the third example, 36 can be represented as and . Therefore it can be decomposed in at least two ways.
解题思路
分解质因数
分类讨论:
首先要求 为 的倍数,另外 能分出 则尽量分出,假设还剩 ,如果 为 非质数,则其可以分出多个质数形成至少两种方案;否则如果 为 质数,特判 的情况,如果 为质数时,则其方案总是一种即本身;如果只能分出 个 ,则无论 怎么分配都只有一种方案;如果可以分出多于 个 ,拿出一个 出来,如果 质因数分解的质数个数大于 的话,可以把每个质因数分开分配,否则假设 只有一个质数且数量为 ,已分配的 每个至多分配到 个质数,如果总的数量大于这个数值则总会有一个已分配的 不满足条件,,为了满足要求,应使剩余的数越小越好,分配出的 越多越好,这样分配出去的数越小更容易满足要求
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/15996655.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!