#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

算法分析:在大地图中找子地图,注意:子地图的方向不确定,也就是说,子地图可以旋转4次90度,产生4中形态。
只要大地图中,有其中任意一种形态,那个位置就是合法的。找出所有这样的状态。
一开始我想把子地图存储成二维数组,后来发现要把它变换成共4中形态,变换的语句描述很是麻烦,修饰语法就得写一大堆。
为了一下xu建哥有什么好的策略:可以把子图存储成一维数组。然后按照四中形态的遍历顺序去大地图中进行遍历。看看在
当前的i,j,能不能遍历出这样的序列,如果能就说明这个位置合法,直接输出。否则继续枚举寻找。
代码:
#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <ctype.h> using namespace std; char ch[202][202];
char c[11]; bool test_ok(int dd, int ff)
{
int i, j;
int k=0;
int ok=1;
for(i=dd; i<=dd+2; i++)
{
for(j=ff; j<=ff+2; j++)
{
if(ch[i][j]==c[k])
{
k++;
}
else
{
ok=0; break;
}
}
if(ok==0)
break;
}
if(ok==1)
{
return true;
}
ok=1; k=0;
for(j=ff; j<=ff+2; j++)
{
for(i=dd+2; i>=dd; i--)
{
if(ch[i][j]==c[k])
k++;
else
{
ok=0; break;
}
}
if(ok==0)
break;
}
if(ok==1)
return true; ok=1; k=0;
for(i=dd+2; i>=dd; i--)
{
for(j=ff+2; j>=ff; j--)
{
if(ch[i][j]==c[k])
k++;
else
{
ok=0; break;
}
}
if(ok==0)
break;
}
if(ok==1)
return true; ok=1; k=0;
for(j=ff+2; j>=ff; j--)
{
for(i=dd; i<=dd+2; i++)
{
if(ch[i][j]==c[k])
k++;
else
{
ok=0; break;
}
}
if(ok==0)
break;
}
if(ok==1)
return true; return false;
} int main()
{
int n, m;
scanf("%d %d", &n, &m);
int i, j;
char cc;
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
cc=getchar();
while(!isalpha(cc)&&cc!='.' ) //不是字母且不是.
{
cc=getchar();
}
ch[i][j]=cc;
}
} //建立地图
int e=0;
for(i=0; i<3; i++)
for(j=0; j<3; j++)
{
cc=getchar();
while(!isalpha(cc)&&cc!='.')
cc=getchar();
c[e++]=cc;
}
c[e]='\0';
//printf("%s", c);
//建立小地图
for(i=0; i<=n-3; i++)
{
for(j=0; j<=m-3; j++)
{
if(test_ok(i, j))
{
printf("%d %d\n", i+1+1, j+1+1);
}
}
}
return 0;
}

hihocoder #1094 : Lost in the City微软苏州校招笔试 12月27日 (建图不大【暴力枚举】 子图的4种形态 1Y )的更多相关文章

  1. hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )

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

  2. hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)

    #1103 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorit ...

  3. Hihocoder #1095 : HIHO Drinking Game (微软苏州校招笔试)( *【二分搜索最优解】)

    #1095 : HIHO Drinking Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playin ...

  4. 苏州Uber优步司机奖励政策(12月21日到12月27日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  5. hihoCoder #1106 : Koch Snowflake 微软苏州校招笔试(1月17日)

    描述 Koch Snowflake is one of the most famous factal. It is built by starting with an equilateral tria ...

  6. 2018年12月8日广州.NET微软技术俱乐部活动总结

    吕毅写了一篇活动总结,写得很好!原文地址是:https://blog.walterlv.com/post/december-event-microsoft-technology-salon.html ...

  7. SQL点滴6—“微软不认识闰年2月29日”&字符"N"的作用

    原文:SQL点滴6-"微软不认识闰年2月29日"&字符"N"的作用 http://www.cnbeta.com/articles/50580.htm这个 ...

  8. 苏州Uber优步司机奖励政策(12月28日到1月3日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  9. 苏州Uber优步司机奖励政策(12月14日到12月20日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

随机推荐

  1. [Bzoj5358][Lydsy1805月赛]口算训练(预处理+动态开点线段树)

    5358: [Lydsy1805月赛]口算训练 Time Limit: 5 Sec  Memory Limit: 512 MBSubmit: 318  Solved: 105[Submit][Stat ...

  2. Spring配置项之<aop:aspectj-autoproxy />

    通过配置织入@Aspectj切面 虽然可以通过编程的方式织入切面,但是一般情况下,我们还是使用spring的配置自动完成创建代理织入切面的工作. 通过aop命名空间的<aop:aspectj-a ...

  3. Linux下批量替换文件内容和文件名(转)

    1.批量替换指定多个文件的文件内容 在指定目录/your/path里,查找包含old_string字符串的所有文件,并用new_string字符串替换old_string字符串. sed -i &qu ...

  4. atom 隐藏右边的白线

    atom-text-editor.editor .wrap-guide {//隐藏右边的白线visibility: hidden;}

  5. iOS -- YYText富文本

    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: [NSString strin ...

  6. mac 查看系统位数

    uname -a

  7. 学会用core dump调试程序错误

    最来在项目中遇到大型程序出现SIGSEGV ,一直不知道用core dump工具来调试程序,花了近一周的时间,才定位问题,老大很生气,后果很严重,呵呵,事后仔细学习了这块的知识,了解一点core du ...

  8. Content Provider 详解

    几个概念:Cursor. Content provider . Uri  .contentresolver 1. Cursor : 个人理解为数据库中的一行数据,它是每行数据的集合.它是一个类.通过它 ...

  9. windows forget jenkins password.

    1. goto the directory of jenkins. for example my installation is in D:\Program Files (x86)\Jenkins. ...

  10. 【Access2007】Access2007的打开方式

    Access2007提供了多种打开方式 仅仅读与非仅仅读就不用说了,就是能编辑与不可以编辑的差别 是否以独占的方式打开是Access2007的打开方式的核心 这里什么都没有写的打开是指以"共 ...