Codeforces should be easier to compete in TC games, but it is a pity that the third question was not shot that night. It may be that the time was not enough, stuck in the first question for too long, a little tragedy ....
A. Rind Road
This question was previously taken as a graph theory question. I didn't see the question clearly, and it was written half an hour before the competition. It was actually very simple, there are n cities and n one-way streets. All cities are connected to one ring through one-way streets. Each one-way street has a weight C. If you want to change one-way streets to one direction, it will cost C. Now our task is to make n one-way streets in the same direction at the lowest price.
My method is to regard the city as a node, and the one-way street as a directed edge, and create a graph. Since n <= 100, we can use the adjacent matrix for storage, and finally start from any point, run the DFS twice in a positive and negative manner. If an edge with a negative weight (the direction of the edge is opposite to that of the traversal), the cost is added to C. At last, a small value of the two fees is output.
Later I thought about how to run DFS only once, and then subtract the sum of weights from the first value, which is the value we get from the second DFS.
My original code.
# Include <cstdio> <br/> # include <iostream> <br/> # include <cstring> <br/> # include <cstdlib> <br/> # include <Algorithm> <br/> using namespace STD; <br/> int A [101] [2], W1 [101] [2], total, total1, Mark [105]; </P> <p> void DFS (int u) <br/>{< br/> int I; <br/> MARK [u] = 1; <br/> for (I = 0; I <= 1; I ++) <br/> If (! Mark [A [u] [I]) <br/>{< br/> If (W1 [u] [I] <0) <br/> total + = (-W1 [u] [I]); <br/> DFS (A [u] [I]); <br/>}< br/> void dfs1 (int u) <br/>{< br/> int I; <br/> MARK [u] = 1; <br/> for (I = 1; I >= 0; I --) <br/> If (! Mark [A [u] [I]) <br/>{< br/> If (W1 [u] [I] <0) <br/> total1 + = (-W1 [u] [I]); <br/> dfs1 (A [u] [I]); <br/>}</P> <p> int main () <br/>{< br/> int N, I, x, y, w; </P> <p> scanf ("% d", & N); </P> <p> for (I = 0; I <N; I ++) <br/>{< br/> scanf ("% d", & X, & Y, & W ); <br/> If (! A [x] [0]) <br/>{< br/> A [x] [0] = y; <br/> W1 [x] [0] = W; <br/>}< br/> else <br/> {<br/> A [x] [1] = y; <br/> W1 [x] [1] = W; <br/>}< br/> If (! A [y] [0]) <br/>{< br/> A [y] [0] = X; <br/> W1 [y] [0] =-W; <br/>}< br/> else <br/> {<br/> A [y] [1] = X; <br/> W1 [y] [1] =-W; <br/>}</P> <p> total = 0; <br/> DFS (1); <br/> If (W1 [1] [1]> 0) <br/> total + = W1 [1] [1]; <br/> memset (mark, 0, sizeof (Mark); <br/> total1 = 0; <br/> dfs1 (1 ); <br/> If (W1 [1] [0]> 0) <br/> total1 + = W1 [1] [0]; <br/> If (total1 <total) <br/> printf ("% d/N", total1 ); <br/> else <br/> printf ("% d/N", total); <br/>}< br/>
B. F1 champions
This is the fastest question I have ever had. Simply sort the question and write the comparison function. I mean there are two criteria for determining the champion of the F1 competition, the first method is to determine the point size. When the points are equal, it determines the number of times the first place is obtained. If the points are equal, it determines the number of times the second place is obtained, and so on. The second method determines the number of times the first place is equal, the points are determined to be equal. If they are equal, the second and third places are compared in sequence...
Write two functions for comparison, sort them twice, and output the first one.
# Include <iostream> <br/> # include <cstdio> <br/> # include <cstring> <br/> # include <cstdlib> <br/> # include <string> <br/> # include <map> <br/> # include <algorithm> </P> <p> using namespace STD; </P> <p> const int rate [] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1 }; <br/> struct node <br/>{< br/> string name; <br/> int point; <br/> int rank [51]; </P> <p> node () <br/> {<br/> name = ""; <br/> point = 0; <br/> memset (rank, 0, sizeof (ran K); <br/>}< br/>} node [51]; <br/> Map <string, int> MP; </P> <p> bool comp1 (const node & A, const node & B) <br/>{< br/> If (. point! = B. point) <br/> return. point> B. point; <br/> for (INT I = 0; I <51; I ++) <br/> If (. rank [I]! = B. rank [I]) <br/> return. rank [I]> B. rank [I]; </P> <p> return. name <B. name; <br/>}</P> <p> bool comp2 (const node & A, const node & B) <br/>{< br/> If (. rank [0]! = B. Rank [0]) <br/> return a. Rank [0]> B. Rank [0]; <br/> else if (A. Point! = B. point) <br/> return. point> B. point; </P> <p> for (INT I = 1; I <51; I ++) <br/> If (. rank [I]! = B. rank [I]) <br/> return. rank [I]> B. rank [I]; </P> <p> return. name <B. name; <br/>}</P> <p> int main () <br/>{< br/> int t, n, CNT = 0, Pos; <br/> string name; <br/> char STR [100]; </P> <p> scanf ("% d", & T ); <br/> while (t --) <br/>{< br/> scanf ("% d", & N); <br/> for (INT I = 0; I <n; I ++) <br/>{< br/> scanf ("% s", STR); <br/> name = STR; <br/> If (MP [name] = 0) <br/>{< br/> CNT ++; <br/> MP [name] = CNT; <br/> node [CNT]. name = Name; <br/>}< br/> Pos = MP [name]; <br/> node [POS]. rank [I] ++; <br/> if (I <10) <br/> node [POS]. point + = Rate [I]; <br/>}</P> <p> sort (node + 1, node + CNT + 1, comp1 ); <br/> printf ("% s/n", node [1]. name. c_str (); <br/> sort (node + 1, node + CNT + 1, comp2); <br/> printf ("% s/n ", node [1]. name. c_str (); </P> <p> return 0; <br/>}< br/>
C. Sequence of Point
This question is relatively simple. I didn't finish writing the code test data during the competition, and I didn't have time to modify it. I gave up and sorted out some formulas:
In this way, we can get the complete formula by adding all the formulas. Because Ai has a period, we can modulo 2N and perform computation. For the convenience of calculation, I have overloaded the operators, it encapsulates the structure of a vertex, which is actually a vector...
Note that when J is given an odd and even number, the symbols before M0 are different.
# Include <iostream> <br/> # include <cstdio> <br/> # include <cstring> <br/> # include <cstdlib> </P> <p> using namespace STD; </P> <p> struct point <br/>{< br/> int X; <br/> int y; </P> <p> point (INT x = 0, int y = 0) <br/>{< br/> This-> X = X; <br/> This-> Y = y; <br/>}< br/> point (const point & Point) <br/>{< br/> X = point. x; <br/> Y = point. y; <br/>}< br/> ~ Point () {}</P> <p> point operator + (const point & P) {return point (x + P. x, Y + P. y) ;}< br/> point operator-(const point & P) {return point (x-p.x, y-p.y) ;}< br/> int operator * (const point & P) {return x * P. X + Y * P. Y ;}< br/> void show () {printf ("% d/N", x, y );} <br/> void set (const Int & x = 0, const Int & Y = 0) <br/>{< br/> This-> X = X; <br/> This-> Y = y; <br/>}< br/>}; </P> <p> point M0, a [100100]; </P> <p> int main () <br/>{< br/> int N; <br />__ Int64 K; <br/> int X, Y; <br/> point RET (0, 0 ); </P> <p> scanf ("% d % i64d", & N, & K); <br/> scanf ("% d", & X, & Y); <br/> m0.set (x, y); <br/> for (INT I = 0; I <n; I ++) <br/>{< br/> scanf ("% d", & X, & Y); <br/> A [I]. set (x, y); <br/>}</P> <p> int Len = K % (2 * n); <br/> bool flag = true; <br/> for (INT I = 0; I <Len; I ++) <br/>{< br/> If (FLAG) <br/> ret = RET + A [(k-i-1) % N]; <br/> else <br/> ret = ret-A [(k-i-1) % N]; <br/> flag =! Flag; <br/>}< br/> ret. x * = 2; <br/> ret. y * = 2; <br/> If (K % 2) <br/> ret = ret-m0; <br/> else <br/> ret = RET + M0; </P> <p> ret. show (); </P> <p> return 0; <br/>}< br/>