Hdu 2425 Hiking Trip

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=2425

Hiking Tripdescription

Hiking in the mountains is seldom a easy task for most people, as it's extremely easy-to-get lost during the trip. Recently Green has decided to go on a hiking trip. Unfortunately, half through the trip, he gets extremely tired and so needs to find the path that would bring him to the Destination with the least amount of time. Can you help him?
You ' ve obtained the area Green's in as a R * C map. Each grid in the map can is one of the four types:tree, sand, path, and stone. All grids not containing stone is passable, and each time, when Green enters a grid of type X (where X can is tree, sand or path), he'll spend time T (X). Furthermore, each time Green can only move up, down, left, or right, provided that the adjacent grid in that direction Exi Sts.
Given Green's current position and he destination, please determine the best path for him.

Input

There is multiple test cases in the input file. Each test case starts with integers R, C (2 <= R <=, 2 <= C <=), the number of Rows/columns DESCRI Bing the area. The next line contains three integers, VP, VS, VT (1 <= VP <=, 1 <= VS <=, 1 <= VT <=), Deno Ting The amount of time it requires to walk through the three types of area (path, sand, or tree). The following R lines describe the area. Each of the R lines contains exactly C characters, each character being one of the following: ' T ', '. ', ' # ', ' @ ', CORRESPO Nding to grids of type tree, sand, path and stone. The final line contains four integers, sr, SC, TR, TC, (0 <= SR < R, 0 <= SC < C, 0 <= TR < R, 0 <= T C < c), representing your current position and your destination. It is guaranteed that Green's current position is reachable–that are to say and it won ' t be a ' @ ' square.
There is a blank line after each test case. Input ends with End-of-file.

Output

For each test case, output one integer in one separate line, representing the minimum amount of time needed to complete th E trip. If there is no-on-Green to reach the destination, output-1 instead.

Sample Input

4 6
1 2 10
T... Tt
ttt###
[Email protected] #T
.. ###@
0 1 3 0

4 6
1 2 2
T... Tt
ttt###
[Email protected] #T
.. ###@
0 1 3 0

2 2
5 1 3
[Email protected]
@.
0 0 1 1

Sample Output

Case 1:14
Case 2:8
Case 3:-1

Bfs+ Priority queue:
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <queue>8#include <map>9 usingstd::cin;Ten usingstd::cout; One usingStd::endl; A usingStd::find; - usingStd::sort; - usingStd::map; the usingstd::p air; - usingstd::vector; - usingStd::multimap; - usingstd::p riority_queue; + #definePB (E) push_back (e) - #defineSZ (c) (int) (c). Size () + #defineMP (A, b) Make_pair (A, B) A #defineAll (c) (c). Begin (), (c). End () at #defineITER (c) Decltype ((c). Begin ()) - #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - Const intN = the; intypedef unsignedLong Longull; - BOOLVis[n][n]; to CharTrip[n][n]; + Const intDx[] = {0,0, -1,1}, dy[] = {-1,1,0,0 }; - intR, C, Vs, Vp, Vt, Sx, Sy, Dx, Dy; the structNode { *     intx, y, S; $Node (inti =0,intj =0,intK =0): X (i), Y (j), S (k) {}Panax NotoginsengInlineBOOL operator< (ConstNode &a)Const { -         returns >A.S; the     } + }; A intBFs () { theCLS (Vis,false); +Priority_queue<node>que; -Que.push (Sx, Sy,0)); $Vis[sx][sy] =true; $      while(!Que.empty ()) { -Node tmp =que.top (); Que.pop (); -         if(tmp.x = = Dx && tmp.y = = Dy)returnTmp.s; theRep (I,4) { -             intNX = Dx[i] + tmp.x, NY = dy[i] +tmp.y;Wuyi             Char&ch =Trip[nx][ny]; the             if(NX <0|| NX >= R | | NY <0|| NY >= C)Continue; -             if(ch = ='@'|| Vis[nx][ny])Continue; Wu             if(ch = ='T') Que.push (Node (NX, NY, TMP.S +Vt)); -             Else if(ch = ='.') Que.push (Node (NX, NY, TMP.S +Vs)); About             Else if(ch = ='#') Que.push (Node (NX, NY, TMP.S +Vp)); $Vis[nx][ny] =true; -         } -     } -     return-1; A } + intMain () { the #ifdef LOCAL -Freopen ("In.txt","R", stdin); $Freopen ("OUT.txt","w+", stdout); the #endif the     intK =1; the      while(~SCANF ("%d%d", &r, &C)) { thescanf" %d%d%d", &AMP;VP, &vs, &Vt); -Rep (i, R) scanf ("%s", Trip[i]); inscanf"%d %d%d%d", &AMP;SX, &sy, &AMP;DX, &Dy); theprintf"Case %d:%d\n", k++, BFS ()); the     } About     return 0; the}
View Code

Hdu 2425 Hiking Trip

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.