hihocoder #1094 : Lost in the City微软苏州校招笔试 12月27日 (建图不大【暴力枚举】 子图的4种形态 1Y )
#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 算法分析:在大地图中找子地图,注意:子地图的方向不确定,也就是说,子地图可以旋转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 )的更多相关文章
- hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )
#1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...
- hihocoder #1103 : Colorful Lecture Note微软苏州校招笔试 1月10日(字符串处理+栈)
#1103 : Colorful Lecture Note 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi is writing an algorit ...
- Hihocoder #1095 : HIHO Drinking Game (微软苏州校招笔试)( *【二分搜索最优解】)
#1095 : HIHO Drinking Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playin ...
- 苏州Uber优步司机奖励政策(12月21日到12月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- hihoCoder #1106 : Koch Snowflake 微软苏州校招笔试(1月17日)
描述 Koch Snowflake is one of the most famous factal. It is built by starting with an equilateral tria ...
- 2018年12月8日广州.NET微软技术俱乐部活动总结
吕毅写了一篇活动总结,写得很好!原文地址是:https://blog.walterlv.com/post/december-event-microsoft-technology-salon.html ...
- SQL点滴6—“微软不认识闰年2月29日”&字符"N"的作用
原文:SQL点滴6-"微软不认识闰年2月29日"&字符"N"的作用 http://www.cnbeta.com/articles/50580.htm这个 ...
- 苏州Uber优步司机奖励政策(12月28日到1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 苏州Uber优步司机奖励政策(12月14日到12月20日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
随机推荐
- 配置tomcat启动参数-Dfile.encoding=UTF-8后,IDEA控制台乱码
配置tomcat启动参数-Dfile.encoding=UTF-8后,IDEA控制台出现乱码 解决方法: 在idea的bin目录(如:D:\JetBrains\IntelliJ IDEA 2018.1 ...
- eclipse默认配色(内含恢复文件和恢复方法)
转载:http://blog.csdn.net/w174504744/article/details/8672679 很多搞开发的同学一开始不喜欢默认的eclipse白底配色,去网上千辛万苦搜到了很多 ...
- HDU 5054 Alice and Bob(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5054 Problem Description Bob and Alice got separated ...
- 【KMP】hdu1867(A + B for you again) 杭电java a题真坑
点击打开链接 Problem Description Generally speaking, there are a lot of problems about strings processing. ...
- apollo 消息分发源代码分析
1.MessageDispatch消息分发信息 public static final byte DATA_STRUCTURE_TYPE = CommandTypes.MESSAGE_DISPATCH ...
- 如何去掉Google搜索的跳转 让你的Google搜索不被reset掉
http://www.nowamagic.net/librarys/veda/detail/389 在点击google搜索结果时,google会在结果的URL前做个跳转,且有时这个跳转地址会被墙,这样 ...
- VC++的project文件
VC++的project文件说明: *.dsp:是VC++的项目文件,文本格式. *.dsw:是工作区文件,它能够指向一个或多个.dsp文件. *.clw:是 ClassWizard信息文件,实际上是 ...
- bash 的环境配置文件
http://www.cnblogs.com/ggjucheng/archive/2012/11/01/2750179.html bash 的环境配置文件 你是否会觉得奇怪,怎么我们什么动作都没有进行 ...
- 抽象类的子类能够new
纠结了半天,我以为继承了Activity后不能new这里被那个onCreate方法迷惑了以为会出现故障一直没直接创建对象类使用 后来试了试才知道 activity似乎是一个抽象类吧. 你要用他的方法, ...
- win7-64bit下基于VMware12.5安装rhel-server-6.3-i386
/************************************************************************************* 宿主PC:win7-64b ...