刚开始学习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. iOS静态库及Framework 创建

    本文转自cocoachina,尊重作者的汗水. 讲述的非常透彻,有需要的朋友可以阅读实践.转载请注明出处 //=================以下留着备份==================// 在 ...

  2. Node.js 基础库

    全局对象 Node.js 中的全局对象是 global,所有全局变量(除了 global 本身以外)都是 global对象的属性. 我们在 Node.js 中能够直接访问到对象通常都是 global ...

  3. IntrospectorCleanupListener作用

    <!--web.xml--><listener> <listener-class>org.springframework.web.util.Introspector ...

  4. caroufredsel 参数

    caroufredsel 参数 参数列表:参数名     默认值     说明circular     true     循环模式,true为无限循环,false为单轮循环.infinite      ...

  5. BIOS MCSDK 2.0 学习笔记(二)————使用Platform Library创建工程

    [TOC] Platform Library提供了一组适用于开发板的API函数.我们可以使用它来快速入手开发板. 1.启动CCS,建立一个空的工程 2.添加include路径 "C:\Pro ...

  6. unity调用摄像头的方法

    http://blog.csdn.net/cocoa_china/article/details/10527995 using UnityEngine; using System.Collection ...

  7. gulp详细入门教程-gulp demo download

    简介: gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:她不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成:使用她,我们不仅可以很愉快的编写代码 ...

  8. Maven中的DependencyManagement和Dependencies

    Maven 使用dependencyManagement 元素来提供了一种管理依赖版本号的方式.通常会在一个组织或者项目的最顶层的父POM 中看到dependencyManagement 元素.使用p ...

  9. Vertica并发DML操作性能瓶颈的产生与优化(转)

    文章来源:中国联通网研院网优网管部IT技术研究团队 作者:陆昕 1. 引言 众所周知,MPP数据库以其分布式的超大存储能力以及列式的高速汇总能力,已经成为大数据分析比不可少的工具.Vertica就是这 ...

  10. 使用ef查询有缓存的问题

    使用mvc ef更新后数据之后刷新页面,发现页面的数据没有变,而数据库的数据更新了,找了一点资料,是因为ef6有个缓存机制: Repository 类: //此方法查询结果有缓存 public Lis ...