Codeforces 375 Div2
Title link and Code link
A, B, and D are all very simple. The interpretation of question C is a little off + the range of the array is not judged, GG. I dare not even think about the two structures E and F. . . . Question E has been considering the network flow solution, but I can’t figure out how to build a graph.
A The New Year: Meeting Friends
The shortest distance between three points to the same point.
minus the sum of the absolute values of the median.
B Text Document Analysis
Given a sequence of strings, ask the number of words inside the brackets and the maximum length of the words outside the brackets.
Maintain the current status, within the brackets or outside the brackets, and record the corresponding results for each status.
C Polycarp at the Radio
The question is very convoluted and annoying. . .
The meaning of the question is to give the number of $n$. $a_i$ means that the i-th song is played by the band $a_i$. Now the person wants to redistribute the tracks so that in all cases, the band that plays the least tracks, $1$ to $m$, plays the most.
The final minimum value must be $n/m$.
The scope is not determined well, it is the rewrite allocation written by xjb. For each type of $m$, when the quantity is greater than $n/m+n%m$, give the smaller quantity. If the current number of bands from 1 to m is not enough, take it from the value greater than m or the one with a larger number. Complexity$O(mn)$.
D Lakes in Berland
The meaning of the question is to give the grid of $n*m$, ‘*’ represents land and ‘.’ represents water. A lake refers to a grid connected block surrounded by land. Water that is not bounded by land or connected to a convenient connection belongs to the ocean. Now it is required to change the number of lakes to $k$. Ask how many cells are the minimum changes.
It is purely a deep search of xjb, find the $n-k$ with the smallest area, and calculate the sum.
*E One-Way Reform
Given $n$ points and $m$ edges, these edges now have no direction. You are required to set a direction for each edge so that the number of points with outgoing edge = incoming edge is the largest.
For each oddity point, connect it to the point $n+1$. Then run the Euler circuit and continuously delete edges.
1 | int n, m; |
It is also possible to build a network flow. I always vaguely felt that I had encountered this problem. After reading [this blog] (http://blog.csdn.net/snowy_smile/article/details/52732805), I was even more convinced that I had done it (this kind of network flow problem is still very common. I will try to figure it out next time I encounter a similar one~).
*F st-Spanning Tree
Given $n$ points and $m$ edges, it is required to construct a tree so that the degree of the given two points $s$, $t$ does not exceed $d_s$, $d_t$.
First, put in the edges that do not contain $s$ and $t$ without thinking.
After that, you will find that there are connected blocks one by one. First, look for whether there is a connected block connecting $s$ and $t$. If not, then there must be $s$ and $t$. Connect them. Then connect $s$ to $s$, and connect $t$ to $t$.
If there is a connected block connecting $s$ and $t$, after connecting, $s$ can be connected to $s$, and $t$ can be connected to $t$.