HDU 4584 Building bridges

题意:

思路:

 

#include<cstdio>

#include<iostream>

#include<cstring>

#include<cmath>

#include<stdlib.h>

#include<vector>

#include<queue>

#include<stack>

#include<algorithm>

using namespace std;

const int MAXN=2000+5;

const int MAX=50+5;

const int INF=0x3f3f3f3f;

char str[MAX][MAX];

struct node

{

    int x,y;

}H[MAXN],C[MAXN];



int dis(node A,node B)

{

    return abs(A.x-B.x)+abs(A.y-B.y);

}

int main()

{

    int n,m;

    while(scanf("%d%d",&n,&m) && (n||m))

    {

        for(int i=0;i<n;i++) scanf("%s",str[i]);

        int a=0,b=0;

        for(int i=0;i<n;i++)

        {

            for(int j=0;j<m;j++)

            {

                node temp;

                if(str[i][j] == 'H')

                {

                    temp.x=i;

                    temp.y=j;

                    H[a++]=temp;

                }

                if(str[i][j] == 'C')

                {

                    temp.x=i;

                    temp.y=j;

                    C[b++]=temp;

                }

            }

        }



        int id1=0,id2=0;

        int minn=INF;

        for(int i=0;i<a;i++)

        {

            for(int j=0;j<b;j++)

            {

                if(dis(H[i],C[j])<minn)

                {

                    minn=dis(H[i],C[j]);

                    id1=i;

                    id2=j;

                }

            }

        }

        printf("%d %d %d %d\n",H[id1].x,H[id1].y,C[id2].x,C[id2].y);

    }

    return 0;

}

 

你可能感兴趣的:(bridge)