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 ...
随机推荐
- BZOJ 1044 木棍分割(二分答案 + DP优化)
题目链接 木棍分割 1044: [HAOI2008]木棍分割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3830 Solved: 1453[S ...
- Android 防护扫盲篇
一,已知防护策略 1.不可或缺的混淆 Java 是一种跨平台.解释型语言,Java 源代码编译成的class文件中有大量包含语义的变量名.方法名的信息,很容易被反编译为Java 源代码.为了防止这种现 ...
- upper_bound——自己的实现
int BSearch() { int ln(1),rn(n+1); while(ln+1<rn) { int mid=(ln+rn)>>1; if (Check(mid)) { l ...
- spring版本不兼容JDK问题
在实验书上Spring项目的时候出现一个问题,导入包和使用注释的时候eclipse出现报错. 导入包报错:The import org cannot be resolved 注释报错:componen ...
- java保留n位小数
double x = 123456789.987654312; String.format("%.nf", x) n为保留的小数位,x必须为double类型. 例如保留3位小数 S ...
- tensorflow提示出错'module' object has no attribute 'pack'
编译旧的代码,会像下面这样提示出错: deconv_shape3 = tf.pack([shape[0], shape[1], shape[2], NUM_OF_CLASSESS]) Attribut ...
- linux下命令行的查找顺序
由下可知,linux通过$PATH的路径顺序,由左至由依次查找某个程序,如果有两个路径下都有这个程序,以先找到的为准 [rpc_server]$ which 23/usr/bin/which: no ...
- iOS开发 编码规范
转至 http://www.cnblogs.com/celestial/archive/2012/06/30/2571417.html 编码规范 一.文档结构管理 1.建立Libraries文件夹 ...
- [反汇编练习] 160个CrackMe之032
[反汇编练习] 160个CrackMe之032. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- 深度排序与alpha混合 【转】
翻译:李现民 最后修改:2012-07-03 原文:Depth sorting alpha blended objects 先说个题外话,本来我想回答在 Creators Club论坛上的一个常见 ...