CF526ABCDE,智能abc怎麼打cf空格
XGG Blog
- CF526A King of Thieves
- CF526B Om Nom and Dark Park
- CF526C Om Nom and Candies
- CF526D Om Nom and Necklace
- CF526E Transmitting Levels
CF526A King of Thieves
Brute force.
Code
CF526B Om Nom and Dark Park
Add minimum lights from bottom to top.
Code
CF526C Om Nom and Candies
Square root.
Code
CF526D Om Nom and Necklace
Use KMP to find the pattern of repetition. Let next[i] be the backward pointer when the matching is failed, if i % (i - next[i]) == 0, then the minimum length of repetend is i - next[i], which repeats i / (i - next[i]) times. If i % (i - next[i]) != 0, then i % (i - next[i]) is the length of the prefix before the repetends.
For this problem, let S=A+B+A+B+A+⋯+A+B+A=R+R+⋯+T, where T is a prefix of R.
When T=R, denote the number of R by r, then the number of R in A is (rmodk), A appears k+1 times, thus (rmodk)∗(k+1)≤r, (rmodk)≤⌊rk⌋.
When T≠R, then the number of R in A is also (rmodk), note that one R must be used for the prefix T, thus (rmodk)<⌊rk⌋.
Code
CF526E Transmitting Levels
Find the minimal length of maximal valid blocks from 1 to 2n, then the start position in the cycle must be in this block.
Code