F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Treasure Hunting

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2457    Accepted Submission(s): 683


Problem Description
Do you like treasure hunting? Today, with one of his friend, iSea is on a venture trip again. As most movie said, they find so many gold hiding in their trip.
Now iSea¡¯s clever friend has already got the map of the place they are going to hunt, simplify the map, there are three ground types:

¡ñ '.' means blank ground, they can get through it
¡ñ '#' means block, they can¡¯t get through it
¡ñ '*' means gold hiding under ground, also they can just get through it (but you won¡¯t, right?)

What makes iSea very delighted is the friend with him is extraordinary justice, he would not take away things which doesn¡¯t belong to him, so all the treasure belong to iSea oneself!
But his friend has a request, he will set up a number of rally points on the map, namely 'A', 'B' ... 'Z', 'a', 'b' ... 'z' (in that order, but may be less than 52), they start in 'A', each time friend reaches to the next rally point in the shortest way, they have to meet here (i.e. iSea reaches there earlier than or same as his friend), then start together, but you can choose different paths. Initially, iSea¡¯s speed is the same with his friend, but to grab treasures, he save one time unit among each part of road, he use the only one unit to get a treasure, after being picked, the treasure¡¯s point change into blank ground.
Under the premise of his friend¡¯s rule, how much treasure iSea can get at most?

 

Input
There are several test cases in the input.

Each test case begin with two integers R, C (2 ¡Ü R, C ¡Ü 100), indicating the row number and the column number.
Then R strings follow, each string has C characters (must be ¡®A¡¯ ¨C ¡®Z¡¯ or ¡®a¡¯ ¨C ¡®z¡¯ or ¡®.¡¯ or ¡®#¡¯ or ¡®*¡¯), indicating the type in the coordinate.

The input terminates by end of file marker.
 

Output
For each test case, output one integer, indicating maximum gold number iSea can get, if they can¡¯t meet at one or more rally points, just output -1.

 

Sample Input
2 4 A.B. ***C 2 4 A#B. ***C
 

Sample Output
1 2
 

Author
iSea @ WHU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 16:35:55, Gzip enabled