6

Codeforces Round #375 (Div.2) Editorial

 1 year ago
source link: http://codeforces.com/blog/entry/47502
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

723A - The New Year: Meeting Friends

To solve this problem you need to understand that friends must meet in the middle point of the given points, so friends who live in the leftmost and in the rightmost points must go to the middle point. Because of that the answer equals to max(x1, x2, x3) - min(x1, x2, x3).

723B - Text Document Analysis

It is an implementation problem. Let's store in the variable cnt the number of words inside brackets and in the variable maxL — the maximum length of the word outside brackets. You can add the symbol «_» to the end of the given string, to correctly process the last word.

Let's iterate through the given string from the left to the right and store in the variable cur the current word. Also in the variable bal we need to store balance of the open and close brackets.

If the current symbol is letter — add it to the end of the string cur and go to the next symbol of the given string.

If the current symbol is open bracket, make bal = bal + 1. If the current symbol is close bracket, make bal = bal - 1. After that if cur is non-empty string add 1 to cnt if bal equals to 1. Else if bal equals to 0 update maxL with length of the string cur. After that we need to assign cur to the empty string and go to the next symbol of the given string.

723C - Polycarp at the Radio

It is easy to understand that we always can get the maximum value of the minimum of the values bj which equals to n / m. So, we need to make vector can which will store positions of the given array in which we will change values. At first it is all positions of the given array, in which the values are more than m. Then we need to store for all i from 1 to m in vectors posi the positions of the given array, in which the bands equal to i. Then for every vector, which size is more than n / m we need to add tje first sz(posi) - (n / m) elements in the vector can, where sz(posi) is the size of the vector posi.

After that we need to iterate through the numbers of bands from 1 to m. If sz(posi) is less than n / m we need to take regular (n / m) - sz(posi) positions from the vector can and change the values in this positions to i. In the same time we need to count the number of changes in the playlist.

723D - Lakes in Berland

To solve this problem we need to find all connected components consisting of dots, which do not have common border with ocean. For that we need to implement depth search which returns vector of the points from which the current connected component consists.

Then we need to sort all connected components in order of increasing of their sizes and changes all dots on asterisks in components, beginning from the component with minimum size, until the number of left components does not equals to k.

723E - One-Way Reform

Let's solve this problem for each connected component separately.

At first we need to understand fact that in each connected component there are even number of vertices with odd degree. Let in the current connected component there are k vertices with odd degree and they have numbers o1, o2, ..., ok. Then we need to add in graph non-directional edges (o1, o2), (o3, o4), ... (ok - 1, ok). So in the current component now all vertices have even degree and there is exist Euler cycle, which we need to find and orientate all edges in the order of this cycle. It is easy to show that after that for all vertices which had even degree before we added the edges in-degree is equal to out-degree. In the other words, we show that the maximum number of vertices with equal in- and out-degrees in orientated graph equals to the number of vertices with even degree in non-orientated graph.

After we found Euler cycles for all connected components we need to print orientation of the edges and be careful and do not print edges which we added to the graph to connect vertices with odd degrees.

723F - st-Spanning Tree

At first lets delete vertices s and t from the graph, find all connected components in the remaining graph and build for every component any spanning trees.

Now we need to add in spanning tree vertices s and t. At first let add edges from s to all components, which have no edges to t. Then let add edges from t to all components, which have no edges to s.

If after that the degree of s became more than ds or the degree of t became more than dt answer does not exist.

Now we have components which have edges and to s and to t. Also currently we have two spanning trees which does not connect. Let's choose how to connect them — with vertex s, with vertex t or with both of them (only if we have in the graph an edge {s, t}). For each option we need to greedily connect remaining components (if it is possible for current option). If we done it for any option we need only to print the answer.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK