# #1094 : Lost in the City

247人阅读 评论(0)

### 描述

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

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;

vector<string> Change(vector<string>& vstr)
{
vector<string> vstr2;
string s;
s=vstr[2].substr(0,1)+vstr[1].substr(0,1)+vstr[0].substr(0,1);
vstr2.push_back(s);

s.clear();
s=vstr[2].substr(1,1)+vstr[1].substr(1,1)+vstr[0].substr(1,1);
vstr2.push_back(s);

s.clear();
s=vstr[2].substr(2,1)+vstr[1].substr(2,1)+vstr[0].substr(2,1);
vstr2.push_back(s);

return vstr2;
}

int main()
{
//freopen("in.txt","r",stdin);
int N,M,i,j,k;
string str;
vector<string> street; //字符串动态数组,存储原始街道信息
vector<vector <string > > area(4);   //存储小hi周围信息

cin>>N>>M; //N行 M列
for(i=0;i<N;i++)
{
cin>>str;
street.push_back(str);
}
for(i=0;i<3;i++)
{
cin>>str;
area[0].push_back(str);
}
//-----------------开始处理------------------------------

//1、将area转动，枚举为3种情况
area[1]=Change(area[0]);
area[2]=Change(area[1]);
area[3]=Change(area[2]);

//2、查找

int x1,x2,x3,pos=0;
for(i=0;i<N-2;i++)//N-2行查找area的首行
{
for(k=0;k<M-2;k++)//列数
{
for(j=0;j<4;j++) //4个area分别查找
{
x1=street[i].find(area[j][0],k);//返回s2在s1中第一次出现的位置,找不到则返回-1
if(x1!=k)
continue;
else
{
x2=street[i+1].find(area[j][1],x1);
if(x2!=x1)
continue;
else
{
x3=street[i+2].find(area[j][2],x2);
if(x3!=x2)
continue;
else
{
cout<<i+2<<" "<<x3+2<<endl;
pos=x3+1;//新的查找位置
break;
}
}
}
}
//  if(pos==0)
//  break;

}

}

return 0;
}

2
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：2244次
• 积分：75
• 等级：
• 排名：千里之外
• 原创：5篇
• 转载：1篇
• 译文：0篇
• 评论：3条
文章分类
阅读排行
评论排行
最新评论