刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正。

时间限制: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

解决思路

从(2,2)开始到(n-1,m-1)的方块中的每一个元素进行分析,看其是否满足。分析元素过程:首先顺时针

分析离得最近的四个如果满足,再顺时针分析四个角上的是否满足(注意一旦四个最近的顺序确定了

那么四个角上的顺序也就定下来了)。最后输出所有满足条件的结果。

#include<stdio.h>

int JudgeThePos(char **Map,int i,int j);

char HPos[][];
char HPosDir[],HPosOblDir[],HPosPos;
int n,m; int main()
{
char **Map,EKey;
int i,j;
scanf("%d%d",&n,&m);
//初始化地图
Map=(char **)malloc(n*sizeof(char*));
for(i=;i<n;i++)
Map[i]=(char *)malloc(m*sizeof(char*));
scanf("%c",&EKey);
for(i=;i<n;i++)
{
for(j=;j<m;j++)
scanf("%c",&Map[i][j]);
scanf("%c",&EKey);
}
//读取位置
for(i=;i<;i++)
{
for(j=;j<;j++)
scanf("%c",&HPos[i][j]);
scanf("%c",&EKey);
}
//初始化位置
HPosDir[]=HPos[][]; HPosDir[]=HPos[][];
HPosDir[]=HPos[][]; HPosDir[]=HPos[][];
HPosOblDir[]=HPos[][]; HPosOblDir[]=HPos[][];
HPosOblDir[]=HPos[][]; HPosOblDir[]=HPos[][];
HPosPos=HPos[][];
//对(2,2)到(n-1,m-1)的方块内的每一个位置进行判断
for(i=;i<n-;i++)
{
for(j=;j<m-;j++)
{
if(JudgeThePos(Map,i,j)==)
printf("%d %d\n",i+,j+);
}
}
free(Map);
return ;
} int JudgeThePos(char **Map,int i,int j)
{
int k,l,p,q;
char PosDir[],PosOblDir[],PosPos;
PosDir[]=Map[i-][j];
PosDir[]=Map[i][j+];
PosDir[]=Map[i+][j];
PosDir[]=Map[i][j-];
PosOblDir[]=Map[i-][j+];
PosOblDir[]=Map[i+][j+];
PosOblDir[]=Map[i+][j-];
PosOblDir[]=Map[i-][j-];
PosPos=Map[i][j];
//判断位置
if(PosPos!=HPosPos)
return ;
//判断正方向
for(k=;k<;k++)
{
p=;q=;
for(l=;l<;l++)
{
if((k+p)==)
p=-k;
if(HPosDir[l]==PosDir[k+p])
{
p++;
q++;
}
else
break;
}
if(q==)
break;
}
//判断斜方向
if(q==)
{
p=;q=;
for(l=;l<;l++)
{
if((k+p)==)
p=-k;
if(HPosOblDir[l]==PosOblDir[k+p])
{
p++;
q++;
}
else
break;
}
if(q==)
return ;
else
return ;
}
else
return ;
}

hihoCoder#1094的更多相关文章

  1. hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )

    #1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...

  2. 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 ...

  3. hihoCoder#1094 Lost in the City

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

  4. hihocoder -1121-二分图的判定

    hihocoder -1121-二分图的判定 1121 : 二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Net ...

  5. Hihocoder 太阁最新面经算法竞赛18

    Hihocoder 太阁最新面经算法竞赛18 source: https://hihocoder.com/contest/hihointerview27/problems 题目1 : Big Plus ...

  6. hihoCoder太阁最新面经算法竞赛15

    hihoCoder太阁最新面经算法竞赛15 Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制: ...

  7. 【hihoCoder 1454】【hiho挑战赛25】【坑】Rikka with Tree II

    http://hihocoder.com/problemset/problem/1454 调了好长时间,谜之WA... 等我以后学好dp再来看为什么吧,先弃坑(╯‵□′)╯︵┻━┻ #include& ...

  8. 【hihocoder#1413】Rikka with String 后缀自动机 + 差分

    搞了一上午+接近一下午这个题,然后被屠了个稀烂,默默仰慕一晚上学会SAM的以及半天4道SAM的hxy大爷. 题目链接:http://hihocoder.com/problemset/problem/1 ...

  9. 【hihoCoder】1148:2月29日

    问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...

随机推荐

  1. 谈谈Web前端工程师的定位

    原文地址:http://www.360doc.com/content/10/0708/17/1277406_37692580.shtml 2010-07-08  锋子chans   阅 1116  转 ...

  2. JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参

    <script src="jquery.min.js" type="text/javascript"></script> <scr ...

  3. 误删除libc.so.6 恢复

    一.我是怎样一步一步毁掉系统的 最近在centos 7上进行开发.由于需要使用高版本linux内核的特性,需要将linux内核升级.按照教程:centos 7升级内核 进行升级的时候发现在安装elre ...

  4. IDEA建立---- java web项目

    1.新建一个javaweb项目 2.给项目命名 3.建立完的项目结构大概是这样(在web 下新建 两个目录lib 和 classes) 4.找到project Structure---------&g ...

  5. Security » Authorization » 通过映射限制身份

    Limiting identity by scheme¶ 通过映射限制身份(这部分有好几个概念还不清楚,翻译的有问题) 36 of 39 people found this helpful In so ...

  6. ActiveReports中自定义Winforms的Viewer 工具栏

    ActiveReports中提供不同平台的报表浏览器来加载报表,而不同平台的报表浏览器功能也不一致,今天我们来学习如何定制Winforms Viewer控件. 预览效果: 核心代码: C# // C# ...

  7. python——操作Redis

    在使用django的websocket的时候,发现web请求和其他当前的django进程的内存是不共享的,猜测django的机制可能是每来一个web请求,就开启一个进程去与web进行交互,一次来达到利 ...

  8. 如何在VISIO 2010/2013 中关闭Shape protection(图形保护)

    最近在画UML图,用到MS visio 2010, 在使用一些网络查找到的图形的时候发现无法编辑,在网上找了找,翻译了下. Visio 2013 的图形保护功能,可以锁定图形的某些特定属性,使其无法被 ...

  9. plsql dev

    访问v$session,v$sesstat and v$statname视图的权限 grant create session,resource to chf; grantselectonv_$sess ...

  10. ShellExecute调用另外一个进程(demo为一个控制led的一段代码)

     public enum ShowCommands : int         {             SW_HIDE = 0,             SW_SHOWNORMAL = 1,    ...