#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[][];
char c[]; bool test_ok(int dd, int ff)
{
int i, j;
int k=;
int ok=;
for(i=dd; i<=dd+; i++)
{
for(j=ff; j<=ff+; j++)
{
if(ch[i][j]==c[k])
{
k++;
}
else
{
ok=; break;
}
}
if(ok==)
break;
}
if(ok==)
{
return true;
}
ok=; k=;
for(j=ff; j<=ff+; j++)
{
for(i=dd+; i>=dd; i--)
{
if(ch[i][j]==c[k])
k++;
else
{
ok=; break;
}
}
if(ok==)
break;
}
if(ok==)
return true; ok=; k=;
for(i=dd+; i>=dd; i--)
{
for(j=ff+; j>=ff; j--)
{
if(ch[i][j]==c[k])
k++;
else
{
ok=; break;
}
}
if(ok==)
break;
}
if(ok==)
return true; ok=; k=;
for(j=ff+; j>=ff; j--)
{
for(i=dd; i<=dd+; i++)
{
if(ch[i][j]==c[k])
k++;
else
{
ok=; break;
}
}
if(ok==)
break;
}
if(ok==)
return true; return false;
} int main()
{
int n, m;
scanf("%d %d", &n, &m);
int i, j;
char cc;
for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
cc=getchar();
while(!isalpha(cc)&&cc!='.' ) //不是字母且不是.
{
cc=getchar();
}
ch[i][j]=cc;
}
} //建立地图
int e=;
for(i=; i<; i++)
for(j=; j<; j++)
{
cc=getchar();
while(!isalpha(cc)&&cc!='.')
cc=getchar();
c[e++]=cc;
}
c[e]='\0';
//printf("%s", c);
//建立小地图
for(i=; i<=n-; i++)
{
for(j=; j<=m-; j++)
{
if(test_ok(i, j))
{
printf("%d %d\n", i++, j++);
}
}
}
return ;
}

hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )的更多相关文章

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

    #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. hihoCoder #1106 : Koch Snowflake 微软苏州校招笔试(1月17日)

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

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

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

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

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

  7. hihoCoder#1094 Lost in the City

    原题地址 限时10s,所以不用考虑什么算法了,暴力吧 分别按照3x3视野的四个方向去地图上匹配,把符合的地点标记出来,最后统一按照从上到下,从左到右的顺序输出. 代码: #include <io ...

  8. 转 微软Sysinternals Suite工具13年12月版下载

    Sysinternals Suite 是微软出品的一套集成数十个绿色软件的系统工具包.Sysinternals Suite 和IT之家的魔方电脑大师设计一样,里面的各个小工具组件都可以单独拿出来运行, ...

  9. 2015微软创新杯Imaginecup正在进行参赛(报名截止日期2014年12月31日本23:59)

    CSDN高校俱乐部与微软官方合作,2015微软创新杯大赛中国区官网落户CSDN高校俱乐部:http://student.csdn.net/mcs/imaginecup2015 在微软官方设置创新杯中国 ...

随机推荐

  1. layui样式修改记录

    记录以免遗忘: .layui-elem-quote{ padding 15 改为 5 }

  2. ecshop中的$user对象

    ecshop的程序中,有个对象:$user,它是用来处理用户信息的.比如登录.注册,还有就是用来和第三方管理通讯和共享资源的.在user.php中,有一条$user->login($userna ...

  3. [array] leetcode - 35. Search Insert Position - Easy

    leetcode - 35. Search Insert Position - Easy descrition Given a sorted array and a target value, ret ...

  4. php项目报错 Warning: session_start(): open(D:/software/wamp/wamp/tmp\sess_msrjot7f32ciqb1p2hr4ahejg4, O_RDWR) f

    今天一个php项目报错: Warning: session_start(): open(D:/software/wamp/wamp/tmp\sess_msrjot7f32ciqb1p2hr4ahejg ...

  5. [置顶] android ListView包含Checkbox滑动时状态改变

    题外话: 在xamarin android的开发中基本上所有人都会遇到这个小小的坎,的确有点麻烦,当时我也折腾了好一半天,如果你能看到这篇博客,说明你和我当初也是一样的焦灼,如果你想解决掉这个小小的坎 ...

  6. js 自定义html标签属性

    <input type="text" id="txtBox" displayName="123456" /> 获取自定义属性值: ...

  7. css3 结构性伪类选择器

    伪类 选择器 类型 说明 备注 E:first-line 伪元素选择器 选择匹配E元素内的第一行文本 E:first-letter 伪元素选择器 选择匹配E元素内的第一个字符 E:before 伪元素 ...

  8. 在海航云中部署 keepalived

    **本文属自我学习,不适合转载** 1. 准备工作 1.1 网络方面的准备工作 1.1.1 创建安全组 注意这里要添加 vrrp 协议支持,否则 keepalived 将无法正常工作. 1.1.2 创 ...

  9. Webpack 2 视频教程 008 - WDS 端口号等配置相关

    原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...

  10. C# 控件拖动

    https://zhidao.baidu.com/question/2116834779399609987.html [DllImport("user32.dll", EntryP ...