Rescue
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 27106 Accepted Submission (s): 9600
Problem Descriptionangel was caught by the moligpy! He was put into prison by Moligpy. The prison is described as a n * M (n, M <=) matrix. There is WALLs, ROADs, and guards in the prison.
Angel ' s friends want to save Angel. Their task Is:approach Angel. We assume that "approach Angel" are to get to the position where Angel stays. When there's a guard in the grid, we must kill him (or his?) to move into the grid. We assume that we moving up, down, right, left takes US 1 unit time, and killing a guard takes 1 unit time, too. And we are strong enough to kill all the guards.
You had to calculate the minimal time to approach Angel. (We can move only up, down, left and right, to the neighbor grid within bound, of course.)
Inputfirst line contains-integers stand for N and M.
Then N lines follows, every line has M characters. "." stands for road, "a" stands for Angel, and "R" stands for each of the Angel ' s friend.
Process to the end of the file.
Outputfor Each test case, your program should output a single integer, standing for the minimal time needed. If Such a number does no exist, you should output a line containing "Poor ANGEL have to stay in the prison all he life."
Sample Input7 8#.#####.#.a#. r.#. #x ..... #.##...##...#.............. Sample Output13 authorchen, Xue Sourcezoj Monthly, October 2003 Recommendeddy
1#include <iostream>2#include <map>3#include <algorithm>4#include <string>5 using namespacestd;6map<string,int>m1,m2;7 intMain ()8 {9 intN,ans;Ten stringstr; One while(cin>>N) A { -ans=0; - m1.clear (); M2.clear (); the for(intI=0; i<n;i++) - { -Cin>>str; - if(M1.count (str)) +m1[str]++; - Else +m1[str]=1; A } at for(intI=0; i<n;i++) - { -Cin>>str; - if(M2.count (str)) -m2[str]++; - Else inm2[str]=1; - } tomap<string,int>:: iterator it; + for(It=m1.begin (); It!=m1.end (); it++) - { theStr=it->First ; *ans+=min (m1[str],m2[str]); $ }Panax Notoginsengcout<<ans<<Endl; - } the}
HDU 1242 Rescue