Codeforces Round 874 (Div. 3) D. Flipper Solution

AI Translated from Chinese Problem D. Flipper Problem: Given an n-permutation p[], select an interval [l, r] (l <= r), construct a new permutation: a[r+1:] + a[l:r].reverse() + a[1:l] (using Python slice notation, i.e., left-closed right-open interval). Find the lexicographically largest permutation that can be constructed. Analysis Assume the answer is represented by $ ans_i $. Initial analysis: when $ r = n $, $ ans_1 = r_n $, otherwise $ ans_1 = r_{n+1} $. To ensure lexicographic maximum, we need to select the largest possible $ r $. ...

2023/05/25 · Allen Wu

UVa 12166 Equilibrium Mobile

AI Translated from Chinese Problem: Luogu UVa 12166 Problem Statement Given a binary tree with depth not exceeding 16, representing a balance scale. Each rod is hung in the center, and the weight of each counterweight is known. What is the minimum number of counterweight weights that need to be modified to balance the scale? — Liu Rujia “Algorithm Competition Introduction Basics” Analysis At first glance, it seems difficult to start with. We can first study what properties a balanced scale has. ...

2023/01/12 · Allen Wu

UVa 1600 Patrol Robot

AI Translated from Chinese Problem: Luogu UVa439 Problem Statement Input an m*n matrix representing a map, where 1 represents obstacles and 0 represents free space. The robot needs to move from (1,1) to (m,n) on the m*n map. Each move can go one cell in one of the four directions (up, down, left, right), and can consecutively cross at most k obstacles. Data satisfies 1 <= m, n <= 20, 0 <= k <= 20. ...

2023/01/11 · Allen Wu

UVa 439 Knight Moves

AI Translated from Chinese First time writing a solution ~ Simple, but got stuck for a while. Finally realized I forgot to zero the array XD Problem: Luogu UVa439 Problem Statement Input two coordinates on an 8×8 chessboard (start and end points. Column: ah, Row: 18). Find the minimum number of moves a Knight needs to get from start to end. Analysis Typical BFS shortest path problem. 2D array id[10][10] stores the step count after taking one more step from this cell. Queues qx, qy store coordinates. ...

2023/01/09 · Allen Wu