First, the basic topic1. UVA 11624 fire! Maze problem multi-source BFS
Test Instructions:
Help Joe get out of a maze of fire spread, where Joe can go up and down in one or four directions per minute, and all the burning squares will spread (the space and the ignition grid have a common edge, the next minute the space will also catch fire). There were some obstacles in the maze, Joe and Fire couldn't get in, and when Joe went to a border lattice we thought he was out of the maze.
Output r row C column maze, #表示墙,. Indicates the open space, J means joe,f is a fire lattice
If you can get out, output a minimum time otherwise, impossible
Ideas:
The fire time of each point is preprocessed first, and can be processed directly with the multi-source BFS.
Then use BFS to find the shortest path from the starting point to the boundary, each time the expansion point to ensure that the time to go to the point is strictly less than the point of fire time
Code:
https://paste.ubuntu.com/p/R4bpSJDGvP/
2. UVA 10047 The Monocycle Maze problem complex state
Test Instructions:
From the starting point to the end point, each second can choose to go forward, left, right, each forward a wheel to the next color, a total of 5 colors, the beginning of the green contact with the ground, north, requires the final green contact with the ground, to reach the target point and the shortest time.
Ideas:
BFS more than two-dimensional state direct simulation can
Code:
https://paste.ubuntu.com/p/QRDxqFxN6F/
3. UVA 10054 The Necklace Euro-pull circuitTest Instructions:
n Beads, the two halves of each bead are made up of different colors. Only the same color can be joined together, asked whether to form a necklace.
Ideas:
Determine the degree of each point is an even number of, to determine the map unicom, attention to a heavy edge. Then use the Rujia Euler loop template.
Code:
https://paste.ubuntu.com/p/9VPsbRh53M/
4. Uvalive 4255 Guess Topological sortTest Instructions:
For a sequence a1,a2,a3,.... an, we can calculate a symbol matrix S, is the above right graph matrix, where S (i,j) represents the sign of Ai+...+aj, give the sequence is not difficult to find the matrix, our task is to find the "inverse problem", that is, to give the matrix, to find out the sequence, Sequence each value greater than-10 is less than 10;
Ideas:
Topology ordering, the idea is to use the Kahn algorithm to sort the topology, because there are a number of points with a value of 0, you must set the same weight as the point.
Code:
https://paste.ubuntu.com/p/VwF7NcWZnx/
5, Uvalive 3523Knights of the Round Table binary graph + dual connected componentsTest Instructions:
Yesn(n≤) Knight,m(≤1000000) hates each other, A Knight of more than 3 knights who are guaranteed to hate each other will not sit in a neighboring position to open a meeting, and ask how many knights must not attend any meeting.
Ideas:
First build the diagram, two knights can be adjacent, then even edge. So the title turns into the number of nodes that are not on any simple odd circle. If figure g is not connected, it is divided into several connected components to solve.
Assuming that the graph G is connected, then the points on the simple circle must belong to a double connected component, so we first find all the two connected components.
the necessary and sufficient condition of the binary graph is that there is no odd circle, which can be obviously obtained: if a two-connected component is a binary graph, then the inside point must not be on the odd circle.
If a two-connected component is not a binary graph, will the dots in it be on the odd circle?
The answer is certain in the odd circle, the first two connected components is not a binary map, then there must be a singular ring C. There are two states for the points inside the connected component, on C and not on C.
In C, the C is a singular circle.
not on C, you can construct a strange circle. on C, take two points U1 and u2,u1 to U2 there are two disjoint paths, and the length of a singular and even, for any point outside of C, because it is within the dual-connected components, V to U1,v to U2 there are disjoint two paths, so that the U1 to the U2 between the existing even-length path , there are also odd-length paths, so v must be surprisingly circled with U1 U2 constructs.
Tidy up the idea is to find out all the two connected components, and then determine whether the two-connected component is a binary graph, if not a binary graph, then the connected component inside the point is can be in the odd circle point, processing all can be in the odd circle point, and then calculate the number of points can not be on the odd circle.
Code:
https://paste.ubuntu.com/p/KjYRQ2rDwR/
Graph theory algorithm and Model (training Guide Bank)