P4771 eight hundred pacesetter Ben North Slope

Topic background

baingbaboom being run to the north! ! !

Title Description

There are only babingbaboom K N * M on a map! ! ! For a point on the map has a  H_ {I, J} H I , J  for the height of this place. Now these babingbaboom wants to go on a hillside north. Obtained from the nearest mountain north by each babingbaboom.

Additional definitions:

mountain:

Around the mountain is no higher than its place. (D Unicom)

In the north:

So that coordinate Babingbaboom is A (A, B) A ( A , B ), the coordinates of the mountain for B (X, Y) B ( X , Y ), the mountain when the north Babingbaboom and only if dis_ {A, B} AX == D I S A , B = = AX

Chebyshev distance:

A(x_1,y_1) \qquad B(x_2,y_2) : \qquad dis_{A,B}=max(|x_1 - x_2|, |y_1 - y_2|)A(x1,y1)B(x2,y2):disA,B=max(x1x2,y1y2)

Input Format

The first three rows positive integers N, M, K. Of 2-N + 1 has M lines each positive integers  H_ {I, J} H I , J  . Of the N + 2-N + K + 1 lines each have two positive integers X_i, Y_i babingbaboom representing each coordinate.

Output Format

K line. If there is such a recent mountain (Chebyshev distance) for each babingbaboom, it outputs the babingbaboom to the mountain of Chebyshev distance; otherwise the output (without quotes (I know that the poor are Poor, but "Pool Babingbaboom!"! I would love to write Pool))

Sample input and output

Input # 1
5 5 5
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
1 2
2 3
3 4
4 5
5 1
Output # 1
Pool Babingbaboom!
Pool Babingbaboom!
1
2
0

Description / Tips

1 \leqslant N,M \leqslant 1e31N,M1e3

1 \leqslant K \leqslant 1e51K1e5

1 \leqslant h_{i,j} \leqslant 1e91hi,j1e9

There gradient data!

Sample Pictures (Star on behalf of a Babingbaboom, on behalf of a red mountain):   (a vertical x, y is horizontal when painting did not pay attention, hold it.

apologize. )

 

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k,h[1005][1005],f[1005][1005];

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-'){
            w=-1;
        }
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*w;
}

int main(){
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            h[i][j]=read();
        }
    }
    memset(f,0x3f,sizeof(f));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(h[i][j]>h[i-1][j]&&h[i][j]>h[i+1][j]&&h[i][j]>h[i][j+1]&&h[i][j]>h[i][j-1]){
                f[i][j]=0;
            }
               else{
                f[i][j]=min(f[i-1][j],min(f[i-1][j-1],f[i-1][j+1]))+1;
            }
        }
    }
    for(int i=1;i<=k;i++){
        int x,y;
        x=read();
        y=read();
        if(f[x][y]>10000){
            printf("Pool Babingbaboom!\n");
        }
        else{
            printf("%d\n",f[x][y]);
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11774715.html