#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. slowhttptest慢攻击工具介绍

    slowhttptest介绍 Slowhttptest是依赖HTTP协议的慢速攻击DoS攻击工具,设计的基本原理是服务器在请求完全接收后才会进行处理,如果客户端的发送速度缓慢或者发送不完整,服务端为其 ...

  2. bzoj 4868: [Shoi2017]期末考试

    Description 有n位同学,每位同学都参加了全部的m门课程的期末考试,都在焦急的等待成绩的公布.第i位同学希望在第ti天 或之前得知所.有.课程的成绩.如果在第ti天,有至少一门课程的成绩没有 ...

  3. OpenStack运维(一):OpenStack项目和用户

    1.添加项目 keystone tenant-create --name=demo [--description tenant-description --enable false] demo:项目名 ...

  4. bat检测文件大小并邮件报警

    rem 获取当前日期 set TimeName=%date:~0,4%%date:~5,2%%date:~8,2% rem 获取文件名 set file=%TimeName%   rem 获取文件大小 ...

  5. 根据图片的路径(绝对路径/相对路径都可以),生成base64的

    根据图片的路径(绝对路径/相对路径都可以),生成base64的 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  6. 使用line-height来垂直居中在安卓设备并不居中,利用ji调整

    先判断智能机浏览器的版本信息:方法有两种,但是第一种兼容性更好,但是使用了device插件 第一种: if (device.android()){ } 第二种: var ua = navigator. ...

  7. git 的回退

    今天下午写了一下午的代码给合并没了 然后晚上觉得还是要好好学习一下git的使用 推荐几个git的教程 https://www.liaoxuefeng.com/wiki/0013739516305929 ...

  8. Javascript高级程序设计笔记 <第五章> 引用类型

    一.object类型 创建object实例的方式有两种: //第一种使用new操作符跟构造函数 var person= new Object(); person.name="小王" ...

  9. Python 学习教程汇总

    Python快速教程http://www.cnblogs.com/vamei/archive/2012/09/13/2682778.html简明Python教程https://bop.molun.ne ...

  10. 关于SPF记录的说明

    详细了解SPF记录的可以查看一下这篇博文:http://www.renfei.org/blog/introduction-to-spf.html 关于 SPF SPF:Sender Policy Fr ...