yl-组题

· · 算法·理论

ps:本篇文章全程都有翻译,无暴力,请放心食用

English words

A to E have excessive water content, ignore them.

F - Not Quite a Palindromic String

First, count the number of 0s and 1s. Let the number of 0s be a and the number of 1s be b. Each good pair reduces either a or b by 2. When a = b, it is possible to construct a 01-string with no good pairs using a and b. Therefore, we only need to check whether a and b can become equal after subtracting 2 up to k times.

G - Down with Brackets

It can be observed that strings like ((())) remain balanced no matter how you delete brackets.
However, for strings like ()(()), deleting the outer () results in )((), which is unbalanced. For strings like (()()), deleting the outer () still leaves them balanced.

Thus, the solution is to remove the two outermost brackets and then check if the string remains balanced.

I - Simple Palindrome

Output a vowel string of length n while minimizing the maximum occurrence count of any letter.

To minimize the contribution, identical letters must be placed consecutively.

J - Replace Character

Replace the first occurrence of the least frequent character with the most frequent character.

K - Good Start

There are three cases:

  1. ____       ____  
    |    |     |    |  
    |____|     |____|        

    If the rectangles are in the same row, the gap between them must be divisible by a.

  2. ____        
    |    |      
    |____|      
    ____      
    |    |    
    |____|    

    If the rectangles are in the same column, the gap between them must be divisible by b.

  3. ____       
    |    |      
    |____|       
            ____  
           |    |  
           |____|        

    For cases not covered above, the vertical gap must be divisible by b, and the horizontal gap must be divisible by a.

    Chinese words

    A到E水分过多,不予理睬

F - Not Quite a Palindromic String

先计算 0 和 1 的个数,0 的个数记为 a ,1 的个数记为 b。每次好对都会将 a 或 b - 2,当 a=b 时才可以利用 a 和 b 构造无好对 01 串。所以,只需计算 a 和 b 在经过 kkk 次减 2 后能否相等就行了。

G - Down with Brackets

发现,形如这样的 ((()))都是不管怎么删都还平衡 但是()(())这样的只要删除旁边的()变为)((),如果像这样(()())删除旁边的()还平衡

所以删去左右两个括号,再检测是否平衡即可。

I - Simple Palindrome

输出一个长度为 n 的元音字符串,同时最小化最多字母的出现次数。

相同的字母一定要放一起,才能产生最小贡献

J - Replace Character

将第一个出现的出现次数最少的字母变为出现次数最多的字母即可。

K - Good Start

分为三种情况,

  1. 
    ____       ____
    |    |     |    |
    |____|     |____|     
在一行上,只要中间间隙可以被a整除就行

2.
```cpp
 ____      
|    |    
|____|    
 ____    
|    |  
|____|  

在一列上,只要中间间隙可以被b整除就行

  1. 
    ____     
    |    |    
    |____|   
             ____
            |    |
            |____|     

不属于1和2,只要上下间隙可以被b整除,左右间隙可以被a整除就行