#1094 : Lost in the City

描述

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;
}

• 本文已收录于以下专栏：

hihoCoder - 1094 - Lost in the City （暴力枚举！！）

#1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi g...
• u014355480
• 2015年02月03日 22:20
• 1709

hihocoder-#1094 : Lost in the City

#1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in th...
• zmq570235977
• 2016年04月04日 13:19
• 367

hihocoder 1094 : Lost in the City

• zs709379096
• 2017年07月24日 18:42
• 99

hihocoder #1094 : Lost in the City

• taoyanqi8932
• 2016年08月26日 20:25
• 432

hiho #1094 : Lost in the City

• Chendehaial
• 2016年12月29日 12:11
• 194

hihoCoder 1094 Lost in the City

• piaocoder
• 2015年08月03日 17:16
• 339

hihoCoder #1094 : Lost in the City

• qq_38777624
• 2017年07月03日 21:49
• 90

#1094 : Lost in the City

• jimmy0513
• 2015年01月30日 16:19
• 381

【hihocoder】#1094 : Lost in the City

• yeqiuzs
• 2016年10月04日 15:12
• 1068

#1094 Lost in the City

#1094 Lost in the City. 暴力枚举
• u010049298
• 2015年06月24日 20:27
• 399

举报原因： 您举报文章：#1094 : Lost in the City 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)