刚开始学习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. Bluetooth Low Energy 嗅探

    Bluetooth Low Energy 嗅探 路人甲 · 2015/10/16 10:52 0x00 前言 如果你打开这篇文章时期望看到一些新的东西,那么很抱歉这篇文章不是你在找的那篇文章.因为严格 ...

  2. 别不信!App三年内将被HTML5顶替彻底消失?

    2007年W3C(万维网联盟)立项HTML5,直至2014年10月底,这个长达八年的规范终于正式封稿. 过去这些年,HTML5颠覆了PC互联网的格局,优化了移动互联网的体验,接下来,HTML5将颠覆原 ...

  3. 自定义view--实现滑动

    1.重写 onInterceptTouchEvent() 拦截触摸事件 是由父控件向子控件传递 默认返回false 返回true,事件被当前的viewGroup进行处理,Touch事件不向下(子控件) ...

  4. C语言的总结

    在C语言考试的中,我成绩不是很好,其实在学习C语言的时候我没有好好去学过,我知道了是我自己的错误,我不应该抱着侥幸的心里去上课的,我会去好好听课的哦l

  5. UINavigationController导航控制器初始化 导航控制器栈的push和pop跳转理解

    (1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最下面,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界 ...

  6. Redis ConnectionException

    JAVA 远程链接Redis服务失败,错误信息如下: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a ...

  7. ActiveReports中如何控制页面的记录数

    在 ActiveReports 中,可以固定报表每页显示的行数,当每页的数据不足固定的行数时,自动通过填补空白行来实现,当然这两种功能仅限于区域报表和页面报表中. 区域报表 在区域报表中,有很多方法来 ...

  8. eclipse中将项目发布到tomcat的root目录

    在eclipse中,将项目直接部署在tomcat的root目录中,这样便可以直接ip:port访问项目: 项目右键->属性->web project settings

  9. kaggle数据挖掘竞赛初步--Titanic<数据变换>

    完整代码: https://github.com/cindycindyhi/kaggle-Titanic 特征工程系列: Titanic系列之原始数据分析和数据处理 Titanic系列之数据变换 Ti ...

  10. 使用dreamweaver去掉文本中的空格和换行

    当我们从其他地方拷贝文本到网页,在html代码中会自动带有空格和换行,手动去掉很麻烦,今天试着用dreamweaver去了一下,方法如下: 1.点击Ctrl+F,打开“查找和替换”窗口 2‘见下图: