#1094 : Lost in the City
#1094 : Lost in the City
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
Little Hi gets lost in the city. He does not know where he is.
He does not know which direction is north.Fortunately, Little Hi has a map of the city. The map can be considered as a grid of N*M
blocks. Each block is numbered by a pair of integers. The block at the north-west corner
is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a
character, describing the construction on that block: '.' for empty area, 'P' for parks,'H' for houses, 'S' for streets, 'M' for malls, 'G' for government buildings, 'T' for trees and etc.Given the blocks of 3*3 area that surrounding Little Hi(Little Hi is at the middle block
of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented,
the upper side of the surrounding area may be actually north side, south side,
east side or west side.
输入
Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+1: each line contains M characters, describing the city's map.
The characters can only be 'A'-'Z' or '.'.
Line N+2~N+4: each line 3 characters, describing the area surrounding Little Hi.
输出
Line 1~K: each line contains 2 integers X and Y,
indicating that block (X, Y) may be Little Hi's position.
If there are multiple possible blocks, output them from north to south, west to east.
样例输入
8 8
...HSH..
...HSM..
...HST..
...HSPP.
PPGHSPPT
PPSSSSSS
..MMSHHH
..MMSH..
SSS
SHG
SH.
样例输出
5 4
在大地图中找与小地图匹配的区域即可,Little Hi不知道东南西北,所以四个方向都可能是北,因此需要将地图旋转,任意一个方向匹配即可
C语言:
#include
#include
char c[200][201],Map[10];
int map(int a,int b,int flag)
{int i,j,k=0;char test[10];if(flag==0)//上为北{for(i=a-1; i<=a+1; i++){for(j=b-1; j<=b+1; j++,k++){if(Map[k]!=c[i][j]){return 0;}}}}else if(flag==1)//右为北{for(i=b+1; i>=b-1; i--){for(j=a-1; j<=a+1; j++,k++){if(Map[k]!=c[j][i]){return 0;}}}}else if(flag==2)//下为北{for(i=a+1; i>=a-1; i--){for(j=b+1; j>=b-1; j--,k++){if(Map[k]!=c[i][j]){return 0;}}}}else if(flag==3)//左为北{for(i=b-1; i<=b+1; i++){for(j=a+1; j>=a-1; j--,k++){if(Map[k]!=c[j][i]){return 0;}}}}return 1;
}
int main()
{int n,m,i,j,k,count;char cc;scanf("%d%d",&n,&m);getchar();for(i=0; i
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
