Hdu5433 Xiao Ming climbing (BestCoder Round #55 ($ )),

Source: Internet
Author: User

Hdu5433 Xiao Ming climbing (BestCoder Round #55 ($ )),
Xiao Ming climbingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission (s): 489 Accepted Submission (s): 120


Problem DescriptionDue to the curse made by the dedevil, Xiao Ming is stranded on a mountain and can hardly escape.

This mountain is pretty strange that its underside is a rectangle which size is N m And every little part has a special coordinate (X, y) And a height H .

In order to escape from this mountain, Ming needs to find out the dedevil and beat it to clean up the curse.

At the biginning Xiao Ming has a fighting will K , If it turned 0 Xiao Ming won't be able to fight with the dedevil, that means failure.

Ming can go to next position (N, E, S, W) From his current position that time every step, (Abs (H1 −h2)/k 'S physical power is spent, and then it cost 1 Point of will.

Because of the dedevil's strong, Ming has to find a way cost least physical power to defeat the dedevil.

Can you help Xiao Ming to calculate the least physical power he need to consume.
InputThe first line of the input is a single integer T (T ≤ 10) , Indicating the number of testcases.

Then T Testcases follow.

The first line contains three integers N, m, k , Meaning as in the title (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) .

Then N × M Matrix follows.

In matrix, the integer H Meaning the height (I, j) , And '# 'meaning barrier (Xiao Ming can't come to this ).

Then follow two lines, meaning Xiao Ming's coordinate (X1, y1) And the dedevil's coordinate (X2, y2) , Coordinates is not a barrier.
OutputFor each testcase print a line, if Xiao Ming can beat dedevil print the least physical power he need to consume, or output" NoAnswer "Otherwise.

(The result shocould be rounded to 2 decimal places)
Sample Input

34 4 521342#232#2222211 13 34 4 721342#232#2222211 13 34 4 502#342#232#222#211 13 3

Sample Output
1.030.00No Answer

SourceBestCoder Round #55 ($)
Give you a picture of the minimum physical strength required from the start point to the end point. The formula for calculating the physical strength is (abs (H1 −h2)/k, and k is the current fighting spirit, each step is taken to reduce morale by 1. analysis: for common bfs, you only need to pay attention to the fact that each point may be traversed multiple times. It takes the minimum amount of effort to locate the point, and finally find the final result within these points (see the code for details ).
# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <math. h> # include <algorithm> # include <queue> # include <set> # include <bitset> # include <map> # include <vector> # include <stdlib. h> using namespace std; const double eps = 1e-6; const double pi = acos (-1.0); const int INF = 0x3f3f3f; const int MOD = 1000000007; # define ll long # define CL (a) memset (a, 0, sizeof (a) int n, m, k; int a, B, c, d; doubl E minx; char ch [55]; int mat [55] [55]; double vis [55] [55] [55]; // vis [I] [j] [k] indicates) the physical strength of the k fighting spirit remaining in the coordinates int dir [4] [2] = {0,-1}, {0, 1 }, {100005 }}; struct node {int x, y, t; // t: fighting spirit double ans; // physical strength} s []; void bfs (node st) {queue <node> q; node now, next; st. t = k; st. ans = 0.0; vis [st. x] [st. y] [st. t] = 0; q. push (st); while (! Q. empty () {now = q. front (); if (now. t <= 0) return; for (int I = 0; I <4; I ++) // common bfs {next. x = now. x + dir [I] [0]; next. y = now. y + dir [I] [1]; if (next. x <0 | next. x> = n | next. y <0 | next. y> = m) continue; if (mat [next. x] [next. y] =-1) continue; next. ans = now. ans + (double) abs (mat [now. x] [now. y]-mat [next. x] [next. y])/(double) now. t; next. t = now. t-1; if (vis [next. x] [next. y] [next. t]-next. ans> 0) // the current physical strength is smaller than the previous physical strength. {vis [next. x] [next. y] [next. t] = next. ans; // update q. push (next); // enter the queue} q. pop () ;}return ;}int main () {int T; scanf ("% d", & T); while (T --) {scanf ("% d", & n, & m, & k); for (int I = 0; I <n; I ++) {scanf ("% s", ch); for (int j = 0; j <m; j ++) {if (ch [j] = '#') mat [I] [j] =-1; else mat [I] [j] = ch [j]-'0' ;}} scanf ("% d ", & a, & B); scanf ("% d", & c, & d); if (k <= 0) {printf ("No Answer \ n"); continue;} a --, B --, c --, d --; node st; st. x = a; st. y = B; // CL (vis); for (int I = 0; I <= n; I ++) // initialize for (int j = 0; j <= m; j ++) for (int r = 0; r <= k; r ++) vis [I] [j] [r] = INF; bfs (st); minx = vis [c] [d] [1]; for (int I = 1; I <= k; I ++) // scan the last one to obtain the minimum physical strength minx = min (minx, vis [c] [d] [I]); if (minx-INF <0) printf ("%. 2lf \ n ", minx); else printf (" No Answer \ n ");} return 0 ;}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.