hiho week 66 register

Ended

Participants:488

Verdict:Accepted
Score:100 / 100
Submitted:2015-10-05 21:22:38

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<stdio.h>
#include<queue>
using namespace std;
queue<pair<pair<int,int>,int> >Q;
char M[111][111];
int dx[]={-1,+1, 0, 0};
int dy[]={ 0, 0,-1,+1};
int s[111][111];
int main()
{
    int n,m,i,j,k,fx,fy,tx,ty,ans;
    pair<pair<int,int>,int>frt;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)scanf("%s",M[i]);
    for(i=0;i<n;i++)
    for(j=0;j<m;j++)
    if(M[i][j]=='H')Q.push(make_pair(make_pair(i,j),0)),i=n,j=m;
    while(!Q.empty())
    {
        frt=Q.front();
        fx=frt.first.first;
        fy=frt.first.second;
        Q.pop();
        for(i=0;i<4;i++)
        {
            tx=fx+dx[i];
            ty=fy+dy[i];
            if(0<=tx&&tx<n&&0<=ty&&ty<m&&(M[tx][ty]=='.'||M[tx][ty]=='S'))
            {
                if(M[tx][ty]=='.')Q.push(make_pair(make_pair(tx,ty),frt.second+1));
                else s[tx][ty]=frt.second+1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX