hihocoder 第68周 题目1 : Lost in the City

来源:互联网 发布:四季彩软件下载 编辑:程序博客网 时间:2024/06/08 10:08

此题只得了30分,但思路没有错误。可能是边界条件有问题。和图像的模板匹配有些相似。


题目1 : 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.PPGHSPPTPPSSSSSS..MMSHHH..MMSH..SSSSHGSH.
样例输出
5 4

#include<iostream>using namespace std;char s[207][207];char t[3][3],tr90[3][3],tr180[3][3],tr270[3][3];void rotate(char t1[3][3],char t2[3][3]){    for(int i=0;i<3;++i)    for(int j=0;j<3;++j)    t2[i][j]=t1[2-j][i];}int check(char s[][207],char p[][3],int g,int h){    int flag=1;     for(int i=0;i<3;++i)    for(int j=0;j<3;++j)    if(s[g+i][h+j]!=p[i][j])    flag=0;        if(flag==1)    return 1;    else return 0;}int main(){    int n,m;    cin>>n>>m;    for(int i=0;i<n;++i)    //for(int j=1;j<=m;++j)    cin>>s[i];    for(int i=0;i<3;++i)    //for(int j=0;j<3;++j)    cin>>t[i];    rotate(t,tr90);    rotate(tr90,tr180);    rotate(tr180,tr270);        for(int i=0;i<n-2;++i)    for(int j=0;j<m-2;++j)    {        int flag=0;        flag|=check(s,t,i,j);        flag|=check(s,tr90,i,j);        flag|=check(s,tr180,i,j);        flag|=check(s,tr270,i,j);        if(flag){        cout<<i+2<<" "<<j+2<<endl;        return 0;}    }    return 0;}





0 0