[The title is very long] remote control racing car

Source: Internet
Author: User

[Description]

Recently, remote control racing players from all over the country have gathered to participate in the annual csom remote control racing competition. The csom remote control racing competition has a long history. Although during each year's competition, the competition Organizing Committee will set up new rules based on actual needs, some players may be difficult to adapt, but it is precisely because of this spirit of continuous innovation that more people are involved and the competition has also achieved unprecedented success. In the previous csom competitions, a n × m venue was used as the venue, requiring contestants to move from the start point to the end in the shortest time. Although the terrain of the stadium has a little ups and downs, there are no locations that cannot be reached. Therefore, in this competition system, as long as the horsepower of the contestant racing car is large enough, it can take a great advantage. With the past few years of competition, although the performance of the racing car has been greatly improved, but due to technical limitations, the increase has been reduced. In order to make the competition content more novel and more difficult, the csom competition Organizing Committee has developed a new competition rule, the biggest change is the addition of many obstacles that cannot be crossed on the stadium. If a racing car hits an obstacle before it reaches the terminal, it is regarded as a task failure. When the performance of a racing car is quite different, such as the horsepower and flexibility, it is necessary to control the fast speed of the racing car to move around the obstacle to the end, the most important thing is to increase the reaction sensitivity of the contestants (that is, the shortest time between two changes to the direction of the racing car, also known as the reaction time of the contestants ), allows you to quickly control the car and change the way forward. Of course, because of the different reaction sensitivity of contestants, the paths you can select will be very different. As shown in, the response time of the two contestants in the same arena is 2 s and 1 s, respectively, the time required to reach the destination is 18 seconds and 16 seconds respectively (the vehicle can move one cell in the current direction every second and change the direction from the start point ).

(Image is input as an example)

The above two figures show that the shortest route length of a racing car is determined by the reaction sensitivity of the contestant. When the contestant's reaction is slow, there may be no feasible path. Your task is to find all the possible response time of the contestant when you can complete the competition (that is, there is a path from the start point to the end point, and the length of the shortest route corresponding to each possible response time.

[Input format]

The first line of the input file contains two integers n and M, indicating the length and width of the stadium. The second row contains four integers X1, Y1, X2, and Y2, indicating that the start and end points of the competition are (x1, Y1) and (X2, Y2) respectively ). The next n rows are a 01 matrix of n × m. in the matrix, row I, column J, element AIJ = 1 indicates that the position (I, j) in the stadium is the track, AIJ = 0 indicates that there are obstacles in the position (I, j.

[Output format]

The output file may have multiple rows. Each row outputs a possible contestant response time and the shortest route length corresponding to the time. The output file must contain the response time of all contestants meeting The question requirements.

[Example input]

10 10

1 4 10 7

0 0 0 1 0 0 0 0 0

0 0 0 1 1 1 0 0 0 0

0 0 0 1 0 0 0 0

1 1 1 1 0 1 1 1 1 0

1 0 0 0 0 0 0 1 0

1 0 1 1 0 1 1 1 0

1 1 1 0 1 1 1 0 1 0

0 0 1 0 0 0 0 1 0

0 0 1 1 1 1 1 1 1 0

0 0 0 0 0 1 0 0 0

[Sample output]

1 16

2 18

[Analysis]

Apparently the shortest path. Each place that can be accessed is a point. Pay attention to the determination of the edge length. In my diagram, we first connect all the edges, and then limit the edge length (> = T) in the spfa process ). During the first write, t is not enumerated once to create a graph. The limit of the edge length is greater than T, and timeout. A maximum of edges can be created at one point, so the method of the chart is changed. Another point is that the spfa queue is too short ...... So we multiply by another maxn. Well, it's a good question.

# Include <stdio. h> # include <string. h> # define maxn 110 # define maxint 1000000000 bool _ map [maxn] [maxn]; struct SS {int XX, YY, di ;} BL [maxn] [maxn] [5 * maxn]; int num [maxn] [maxn]; int dis [maxn] [maxn]; bool V [maxn] [maxn]; int L, R, t, n, m; int Sx, Sy, ex, ey, ans; int temp; struct SSS {int X, Y ;} Q [maxn * maxn]; bool inmap (int x, int y) {return (x> 0) & (x <= N) & (Y> 0) & (Y <= m);} void findl (int x, int y) {If (! _ Map [x] [Y]) return; int Tx, Ty; Tx = X-1; ty = y; while (inmap (TX, Ty )) & (_ map [TX] [ty]) {BL [x] [y] [++ num [x] [Y]. xx = TX; BL [x] [y] [num [x] [Y]. YY = ty; BL [x] [y] [num [x] [Y]. DI = x-TX; -- TX;} Tx = x; ty = Y + 1; while (inmap (TX, Ty )) & (_ map [TX] [ty]) {BL [x] [y] [++ num [x] [Y]. xx = TX; BL [x] [y] [num [x] [Y]. YY = ty; BL [x] [y] [num [x] [Y]. DI = ty-y; ++ ty;} Tx = x + 1; ty = y; while (inmap (TX, Ty )) & (_ map [TX] [ty]) {BL [x] [y] [++ num [x] [y ]. Xx = TX; BL [x] [y] [num [x] [Y]. YY = ty; BL [x] [y] [num [x] [Y]. DI = TX-X; ++ TX ;}tx = x; ty = Y-1; while (inmap (TX, Ty )) & (_ map [TX] [ty]) {BL [x] [y] [++ num [x] [Y]. xx = TX; BL [x] [y] [num [x] [Y]. YY = ty; BL [x] [y] [num [x] [Y]. DI = Y-ty; -- ty ;}} void solve () {memset (v, 0, sizeof (v); L = r = 0; ans = 0; for (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= m; ++ J) dis [I] [J] = maxint; DIS [SX] [sy] = 0; V [SX] [sy] = 1; Q [0]. X = SX; Q [0]. y = sy; while (L <= r) {Int Tx = Q [l]. x, Ty = Q [l]. y; For (INT I = 1; I <= num [TX] [ty]; ++ I) {int Nx = bl [TX] [ty] [I]. XX, NY = bl [TX] [ty] [I]. YY, Nd = bl [TX] [ty] [I]. di; If (nd <t )&&(! (Nx = ex) & (NY = ey) continue; If (DIS [TX] [ty] + nd <dis [NX] [NY]) {dis [NX] [NY] = dis [TX] [ty] + nd; If (! V [NX] [NY]) {v [NX] [NY] = 1; Q [++ R]. X = NX; Q [R]. y = ny ;}}v [TX] [ty] = 0; ++ l ;}ans = dis [Ex] [ey] ;}int main () {freopen ("racing. in "," r ", stdin); freopen (" racing. out "," W ", stdout); scanf (" % d ", & N, & M); scanf (" % d ", & Sx, & Sy, & Ex, & ey); For (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= m; ++ J) {scanf ("% d", & temp); If (temp) _ map [I] [J] = 1 ;} for (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= m; ++ J) findl (I, j ); for (t = 1; t <= 10; ++ t) {solve (); If (ANS> = maxint) break; printf ("% d \ n ", t, ANS);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.