[NOIP2013] Huarong problem solution

[NOIP2013] Huarong

The first is a more obvious approach.

The entire board, in addition to start, end and spaces, other blocks are equivalent.

For the end, it does not always change, if found to end the search to end, so we do not consider the end.

So need to consider is the location of the space and the location of the start box.

The definition of $ f (i1, j1, i2, j2) $ is

A space where the coordinates $ (i1, j1) $ starting point coordinates $ (i2, j2) $.

For each step, the space can be moved around a movable piece, it will be exchanged with the position of the space. In fact, a space equivalent to the space and move to an adjacent piece. If the piece is the starting point, the starting point will be to update the original coordinate space.

BFS use, plus a number of steps each time, state the number of steps within the queue monotone, a first receive any status (as distinguished from Dijkstra, not the first extraction) is optimal. When you first get the coordinates of the starting point is equal to the end point coordinates, return directly answer.

If the end has not been equal to the coordinates of the start point coordinates of the end point, -1 indicates no solution.

This is actually a practice situation may get through all the answers, it should not be a positive solution.

Complexity O (n²m²q), expect to score 80, is not a good pruning.

 

 

 This question is of positive solutions brings me to the other questions. Advanced Guide 0x25 Sokoban a section title. Also used bfs.

Space running around, in fact, is meaningless if it is not the starting point of around four grid, it will never make the starting point near the end.

So we fixed spaces around the four points of the starting point, to update the status and future with the current status.

Takes out a way to update the exchange directly with a starting point, the second is the switching position of the starting point to another direction.

Because each incremental no guarantee that this time is not guaranteed for the first time got to be the best, so you want to use to run spfa or dijkstra shortest.

If you like Sokoban as double bfs, then you will still tle, even slower than the previous run. Because of the complexity of the not at all down.

This problem is multi-question test, the solution is pretreated, as long as the O (n²m²) for each point to update some other point distance can be.

Guess you like

Origin www.cnblogs.com/skyh/p/11200785.html