刚开始学习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. activity通过onActivityResult间数据交互

    首先要创建2个activity 分别为MainActivity和OneActiivity MainActivity代码如下: package com.tp.soft.app; import andro ...

  2. 团队作业week14

    0 如果你的团队来了一个新队员,有一台全新的机器,你们是否有一个文档,只要设置了相应的权限,她就可以根据文档,从头开始搭建环境, 并成功地把最新.最稳定版本的软件编译出来,并运行必要的单元测试?(在这 ...

  3. Wiki安装

    我们推荐使用Mediawiki. MediaWiki是基于php环境的,所以如果需要使用该类wiki,就要先部署php的环境. wiki下载: https://www.mediawiki.org/wi ...

  4. mysql mybatis-generator plugin 分页

    generator.xml配置如下: plugin必须紧跟context,否则会报错 <?xml version="1.0" encoding="UTF-8&quo ...

  5. 上传文件创建目录 mkdir

    mkdir($save_path,0777,true); $save_path  :文件名 0777:权限 .windows 下面可以忽略 当创建多级文件目录的时候一定要加上 true

  6. Servlet实现简单CRUD

    1.首先在数据库中建表 create database student create table stu( sno char(10), sna char(10), ) insert stu value ...

  7. Android 自定义View

    Android 自定义View流程中的几个方法解析: onFinishInflate():从布局文件.xml加载完组件后回调 onMeasure() :调用该方法负责测量组件大小 onSizeChan ...

  8. sqlite字段属性删除方法

    Sqlite 不支持直接修改字段的名称. 我们可以使用别的方法来实现修改字段名. 1.修改原表的名称 ALTER TABLE table RENAME TO tableOld; 2.新建修改字段后的表 ...

  9. CentOS_7.2安装PHP_5.6

    一.安装依赖包和开发工具: yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* ...

  10. POJ 3278 Catch That Cow

    注:本人英语很渣,题目大意大多来自百度~=0= 题目大意 农民约翰需要抓住他的牛,他和他的牛在一条直线上(估计是一维生物),约翰在N (0 ≤ N ≤ 100,000)处,他的牛在 K (0 ≤ K ...