#1094 : Lost in the City

原创 2015年11月20日 16:57:01
时间限制: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

解决方法:先对带查找字符数组进行枚举为4种情况,再在原字符数组中进行查找,我用STL的vector 和string来做 ,非常考验基本功和逻辑思维,花了大概6个小时终于AC了

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

#1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)

1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)描述Little Hi gets lost in the city. He does not know ...

hihocoder #1094 : Lost in the City

题目连接:http://hihocoder.com/problemset/problem/1094?sid=860836此题是暴力枚举的方法: 1.首先在地图中找到他所在的中心位置,因为,无论他是否...

hiho #1094 : Lost in the City

题目描述: 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. H...

hihoCoder - 1094 - Lost in the City (暴力枚举!!)

#1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi g...

【hihocoder】#1094 : Lost in the City

题目链接:http://hihocoder.com/problemset/problem/1094题目: 描述 Little Hi gets lost in the city. He does n...

#1094 : Lost in the City

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not ...

[HiHoCoder]#1094 : Lost in the City 微软苏州校招笔试 12月27日

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not ...

hihoCoder 1094 Lost in the City

暴力枚举。。。 #include using namespace std; int main(void) { int i, j, n, m; char map[222][222], b[11][...

HIHOCODER#1094 : Lost in the City

 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He doe...

hihoCoder #1094 : Lost in the City

题目地址:http://hihocoder.com/problemset/problem/1094 时间限制:10000ms 单点时限:1000ms 内存限制:256MB ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)