• 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));
        }
    } 
  • 相关阅读:
    利用jmSlip写一个移动端顶部日历选择组件
    JS写的排序算法演示
    jmSlip WEB前端滑屏组件
    如何:使用 Visual Basic 编写基于 Unity3D 的计算器
    验证 .NET 4.6 的 SIMD 硬件加速支持的重要性
    VB 2015 的 闭包(Closure)
    VS "15" 预览 5 中 VB 15 新增的功能
    演练:使用Xamarin.Forms开发产品介绍性质的应用(VB版)
    UWP游戏防内存修改器的方法
    优化win2d实现的萤火虫粒子效果
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/9911000.html
Copyright © 2020-2023  润新知