CODE FESTIVAL 2017 qual B
I feel like I should take more contests and think more while doing them. . .
I have been thinking about question C for two hours and have no idea. I am mentally retarded. . .
I won’t talk about the two water questions AB.
C - 3 Steps
The meaning of the question is to give a connected graph without self-loops and duplicate edges, and then continuously add edges to it. The condition for adding edges is that these two points can be connected by three edges, then these two points can add an edge. Ask how many sides can be added at most.
Actually. . . Think about it in terms of bipartite graphs. . .
Think about it later. . . That makes sense. . .
First of all, this is a connected graph. If it cannot be turned into a bipartite graph, it means there is an odd cycle. Then if you draw it, you will find that any two points can eventually add an edge. The answer is $\frac{n*(n-1)}{2}-m$.
What if it can be turned into a bipartite graph. . . Dyeing black and white is the amount of black * the amount of white - m. . .
1 | int n,m; |
D 101 to 010
The meaning of the question is to give a string and ask for the maximum number of operations to turn 101 into 010.
There are only three situations for the final 1 source:
1:1
2: 111101
3: 101111
In this way, it can be converted into the sum of the substring values of non-overlapping intervals, so that the value of the interval is maximized. Can reach $O(n^2)$.
Situations 2 and 3 above can be preprocessed, and dp can be optimized to $O(n)$.
1 | int n; |