zoukankan      html  css  js  c++  java
  • HDU 1242 Rescue

    Rescue

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 27106    Accepted Submission(s): 9600

    Problem Description
    Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.

    Angel's friends want to save Angel. Their task is: approach Angel. We assume that "approach Angel" is to get to the position where Angel stays. When there's a guard in the grid, we must kill him (or her?) 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 have 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.)
    Input
    First line contains two 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 Angel's friend.
    Process to the end of the file.
     
    Output
    For 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 has to stay in the prison all his life." 
     
    Sample Input
    7 8 #.#####. #.a#..r. #..#x... ..#..#.# #...##.. .#...... ........
     
    Sample Output
    13
     
    Author
    CHEN, Xue
     
    Source
     
    Recommend
    Eddy
     1 #include <iostream>
     2 #include <map>
     3 #include <algorithm>
     4 #include <string>
     5 using namespace std;
     6 map<string,int> m1,m2;
     7 int main()
     8 {
     9     int n,ans;
    10     string str;
    11     while(cin>>n)
    12     {
    13         ans=0;
    14         m1.clear(); m2.clear();
    15         for(int i=0;i<n;i++)
    16         {
    17             cin>>str;
    18             if(m1.count(str))
    19                 m1[str]++;
    20             else
    21                 m1[str]=1;
    22         }
    23         for(int i=0;i<n;i++)
    24         {
    25             cin>>str;
    26             if(m2.count(str))
    27                 m2[str]++;
    28             else
    29                 m2[str]=1;
    30         }
    31         map<string,int>::iterator it;
    32         for(it=m1.begin();it!=m1.end();it++)
    33         {
    34             str=it->first;
    35             ans+=min(m1[str],m2[str]);
    36         }
    37         cout<<ans<<endl;
    38     }
    39 }
  • 相关阅读:
    利用 StartLoadingStatus 和 FinishLoadingStatus 读取数据特别是大数据时增加渐隐渐显等待特效
    在Indicator中添加动态Checkbox,无需绑定数据源,支持全选
    修复DBGrideh使用TMemTableEh在Footers求平均值为0的Bug
    字符串操作之格式化
    关于C#里面SQLite读取数据的操作
    多线程“尚未调用coinitialize” 报错
    自动化脚本运行稳定性(一)——脚本健壮性
    接口测试用例编写规范
    测试计划对应用质量的影响
    MySQL数据操作语句精解
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5874526.html
Copyright © 2011-2022 走看看