zoukankan      html  css  js  c++  java
  • HDU 2612 Find a way

    Find a way

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 25131    Accepted Submission(s): 8195

    Problem Description
    Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.
    Yifenfei’s home is at the countryside, but Merceki’s home is in the center of city. So yifenfei made arrangements with Merceki to meet at a KFC. There are many KFC in Ningbo, they want to choose one that let the total time to it be most smallest.
    Now give you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to the adjacent road by cost 11 minutes.
     
    Input
    The input contains multiple test cases.
    Each test case include, first two integers n, m. (2<=n,m<=200).
    Next n lines, each line included m character.
    ‘Y’ express yifenfei initial position.
    ‘M’    express Merceki initial position.
    ‘#’ forbid road;
    ‘.’ Road.
    ‘@’ KCF
     
    Output
    For each test case output the minimum total time that both yifenfei and Merceki to arrival one of KFC.You may sure there is always have a KFC that can let them meet.
     
    Sample Input
    4 4 Y.#@ .... .#.. @..M 4 4 Y.#@ .... .#.. @#.M 5 5 Y..@. .#... .#... @..M. #...#
     
    Sample Output
    66 88 66
     
    Author
    yifenfei
     
    Source
    #include<queue>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int x11,y11,x22,y22;
    char map[210][210];
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    int n,m,ans=0x7f7f7f7f;
    int vis[201][201],an[201][201][2];
    void bfs(int x,int y,int opt){
        queue<int>quex,quey,step;
        memset(vis,0,sizeof(vis));
        quex.push(x);quey.push(y);
        step.push(0);vis[x][y]=1;
        while(!quex.empty()){
            int nowx=quex.front();quex.pop();
            int nowy=quey.front();quey.pop();
            int nows=step.front();step.pop();
            if(map[nowx][nowy]=='@')    an[nowx][nowy][opt]=nows;
            for(int i=0;i<4;i++){
                int cx=nowx+dx[i];
                int cy=nowy+dy[i];
                int cs=nows+11;
                if(cx>=1&&cx<=n&&cy>=1&&cy<=m&&map[cx][cy]!='#'&&!vis[cx][cy]){
                    quex.push(cx);quey.push(cy);
                    step.push(cs);vis[cx][cy]=1;
                }
            }
        }
    }
    int main(){
        while(scanf("%d%d",&n,&m)!=EOF){
            for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++){
                    cin>>map[i][j];
                    if(map[i][j]=='M'){ x11=i;y11=j; }
                    if(map[i][j]=='Y'){ x22=i;y22=j; }
                }
            bfs(x11,y11,0);bfs(x22,y22,1);
            for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                    if(vis[i][j]&&map[i][j]=='@')
                        ans=min(ans,an[i][j][0]+an[i][j][1]);
            printf("%d
    ",ans);
            ans=0x3f3f3f3f;
            //memset(an,0x7f,sizeof(an));
        }
    } 
  • 相关阅读:
    [基础]RHEL6下LINUX服务器批量部署
    delphi 连接 c++ builder 生成obj文件
    Delphi基本图像处理代码
    Delphi 版本号(D1到XE6),发现一个delphi.wikia.com网站
    Delphi常用排序
    Delphi中用Webbrowser加载百度地图滚轮失效(ApplicationEvents里使用IsChild提前判断是哪个控件的消息)
    判断连个单链表是否交叉,并找到交叉点
    窗体自适应屏幕分辨率
    Zlib压缩算法在Java与Delphi间交互实现(压缩XML交互)
    开机自动启动程序的几种方法
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/9911000.html
Copyright © 2011-2022 走看看