#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. JavaScript类型比较

    JavaScript的类型 原始类型: number string boolean null undefined 对象类型: Object function Array Date ... 隐式转换 + ...

  2. UITableView的性能优化

    UITableView作为ios中使用最频繁的控件之一,其性能优化也是常常要面对的,尤其是当数据量偏大并且设备性能不足时.本文旨在总结tableview的几个性能优化tips,并且随着认识的深入,本文 ...

  3. shell按行读取文件

    这工作小半年了发现以前学的那么多流弊技能都不怎么用,倒是shell用的很多,自己已经从shell小菜鸟一步步走过来,已经要变成大菜鸟=.= 经常需要用shell按行读取配置文件,自己在上面踩了很多坑, ...

  4. lua 批量重命名文件

    local s = io.popen("dir F:\\headicon /b/s") local filelist = s:read("*all") loca ...

  5. kibana提示“Your Kibana index is out of date, reset it or use the X-Pack upgrade assistant.”

    =============================================== 2017/12/15_第1次修改                       ccb_warlock = ...

  6. Python安装和开发环境搭建

    1.官网:http://www.python.org/download/下载安装包,目前最新版本为3.6,安装包很多地方可以下,也可以在360软件管家上下载安装  特别要注意勾选:Add Python ...

  7. js获取手机屏幕宽度、高度

    网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...

  8. Webpack 2 视频教程 014 - 深入理解 Webpack 2 中的 loader

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

  9. 细说MyEclipse调试

     在程序出现问题时,我们需要找到并解决掉这些恼人的Bug,才能使程序顺利的运行下去.但是,当代码很多,程序很大的时候,找起来就很麻烦. 所以,我们需要借助工具——Eclipse/MyEclipse中的 ...

  10. Java中使用LocalDate根据日期来计算年龄

    Java中和日期直接相关的类有很多,平时最常用到的就是java.util package下面的Date和Calendar,需要用到格式的时候还会用到java.text.SimpleDateFormat ...