博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )
阅读量:6508 次
发布时间:2019-06-24

本文共 3011 字,大约阅读时间需要 10 分钟。

#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.PPGHSPPTPPSSSSSS..MMSHHH..MMSH..SSSSHGSH.
样例输出
5 4
算法分析:在大地图中找子地图,注意:子地图的方向不确定,也就是说,子地图可以旋转4次90度,产生4中形态。 只要大地图中,有其中任意一种形态,那个位置就是合法的。找出所有这样的状态。 一开始我想把子地图存储成二维数组,后来发现要把它变换成共4中形态,变换的语句描述很是麻烦,修饰语法就得写一大堆。 为了一下xu建哥有什么好的策略:可以把子图存储成一维数组。然后按照四中形态的遍历顺序去大地图中进行遍历。看看在 当前的i,j,能不能遍历出这样的序列,如果能就说明这个位置合法,直接输出。否则继续枚举寻找。
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 8 using namespace std; 9 10 char ch[202][202]; 11 char c[11]; 12 13 bool test_ok(int dd, int ff) 14 { 15 int i, j; 16 int k=0; 17 int ok=1; 18 for(i=dd; i<=dd+2; i++) 19 { 20 for(j=ff; j<=ff+2; j++) 21 { 22 if(ch[i][j]==c[k]) 23 { 24 k++; 25 } 26 else 27 { 28 ok=0; break; 29 } 30 } 31 if(ok==0) 32 break; 33 } 34 if(ok==1) 35 { 36 return true; 37 } 38 ok=1; k=0; 39 for(j=ff; j<=ff+2; j++) 40 { 41 for(i=dd+2; i>=dd; i--) 42 { 43 if(ch[i][j]==c[k]) 44 k++; 45 else 46 { 47 ok=0; break; 48 } 49 } 50 if(ok==0) 51 break; 52 } 53 if(ok==1) 54 return true; 55 56 ok=1; k=0; 57 for(i=dd+2; i>=dd; i--) 58 { 59 for(j=ff+2; j>=ff; j--) 60 { 61 if(ch[i][j]==c[k]) 62 k++; 63 else 64 { 65 ok=0; break; 66 } 67 } 68 if(ok==0) 69 break; 70 } 71 if(ok==1) 72 return true; 73 74 ok=1; k=0; 75 for(j=ff+2; j>=ff; j--) 76 { 77 for(i=dd; i<=dd+2; i++) 78 { 79 if(ch[i][j]==c[k]) 80 k++; 81 else 82 { 83 ok=0; break; 84 } 85 } 86 if(ok==0) 87 break; 88 } 89 if(ok==1) 90 return true; 91 92 return false; 93 } 94 95 int main() 96 { 97 int n, m; 98 scanf("%d %d", &n, &m); 99 int i, j;100 char cc;101 for(i=0; i

 

转载地址:http://bezfo.baihongyu.com/

你可能感兴趣的文章
<%@ include %>指令和<jsp:include>区别
查看>>
因为文件组 'PRIMARY' 已满 解决办法
查看>>
Flume 读取实时更新的日志文件
查看>>
HDU 2049
查看>>
《Spring1之第十次站立会议》
查看>>
Unity Shader 噪声消融特效 - 剑灵死亡特效
查看>>
Eclipse 自动生成 Ant的Build.xml 配置文件
查看>>
添加一条信息到列表,如果重复就替换,
查看>>
C#基础第五天
查看>>
python 小数相加报错 invalid literal for int() with base 10
查看>>
【ubuntu】linux链接库
查看>>
uva 12325 枚举暴力 b
查看>>
多线程问题(JVM重排序)
查看>>
LeetCode 459 Repeated Substring Pattern
查看>>
POJ 3268 Silver Cow Party
查看>>
Android Camera开发:使用TextureView和SurfaceTexture预览Camera 基础拍照demo
查看>>
EMLS项目推进思考
查看>>
Eclipse快捷键 10个最有用的快捷键
查看>>
2018-2019-1 20165302 实验五 通讯协议设计
查看>>
centos6.5安装LNMP
查看>>