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

代码实现:

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(char** s1, int i, int j, char surround[][])
{
for (int a = i; a< + i; a++)
for (int b = j; b< + j; b++)
{
if (s1[a][b] != surround[a - i][b - j])
return ;
} return ;
}
int main()
{
int n = , m = ;
scanf("%d %d", &n,&m);
getchar();
char** map = (char**)malloc(sizeof(char)*n);
for (int i = ; i<n; i++)
{
map[i] = (char*)malloc(sizeof(char)*m);
fgets(map[i], m+, stdin);
getchar();
}
char surround[][] = { };
for (int i = ; i<; i++)
{
fgets(surround[i], , stdin);
getchar();
}
char surround1[][] = { };
char surround2[][] = { };
char surround3[][] = { };
char position = surround[][];
for (int i = ; i<; i++)
{
for (int j = ; j<; j++)
{
surround1[ - j][i] = surround[i][j];
}
}
for (int i = ; i<; i++)
{
for (int j = ; j<; j++)
{
surround2[ - j][i] = surround1[i][j];
}
}
for (int i = ; i<; i++)
{
for (int j = ; j<; j++)
{
surround3[ - j][i] = surround2[i][j];
}
}
for (int i = ; i<n - ; i++)
{
for (int j = ; j<m - ; j++)
{ if (map[i][j] == position)
{
if (compare(map, i - , j - , surround))
{
printf("%d %d\n", i + , j + );
continue;
}
if (compare(map, i - , j - , surround1))
{
printf("%d %d\n", i + , j + );
continue;
}
if (compare(map, i - , j - , surround2))
{
printf("%d %d\n", i + , j + );
continue;
}
if (compare(map, i - , j - , surround3))
{
printf("%d %d\n", i + , j + );
continue;
}
}
}
}
return ;
}

问题:

使用Visual Studio编译运行样例结果正确,但是提交代码通过G++运行会出现Wrong Answer,若知道原因的话还望请留言告知!

最新文章

  1. Unity中各类物理投射性能横向比较
  2. Android中Bitmap和Drawable
  3. MSP430F5438点亮led
  4. 【转】ButterKnife基本使用--不错
  5. 申请免费的SSL证书(Win7,PowerShell,Let&#39;s Encrypt)
  6. php的2种域名转向写法
  7. UART串口通讯协议
  8. 14-使用glusterfs做持久化存储
  9. 【javascript】获取 格式化时间
  10. Linux基础命令---杀死进程pkill
  11. maven的传递性依赖
  12. 2018.07.03 POJ 3348 Cows(凸包)
  13. python标准库介绍——2 os.path模块详解
  14. Windows10下安装python(配置环境变量)
  15. TinyURL
  16. 【Java学习经历系列-1】19岁的我,没遇见生命中的她,却遇见了java
  17. js中立即执行函数写法理解
  18. 【转】 Pro Android学习笔记(七四):HTTP服务(8):使用后台线程AsyncTask
  19. thinkphp5命令行访问
  20. [转载]php 数组 类对象 值传递 引用传递 区别

热门文章

  1. GCD之并行串行区别
  2. C语言编译过程及数据类型
  3. oracle11g 体系结构详解
  4. dynamics 365 AI 解决方案 —— 微软布局
  5. Tomcat启动一闪而过
  6. Javac 编译原理
  7. 实战系列之 Node.js 玩转 Java
  8. Operating system hdu 2835 OPT
  9. bzoj2257 [Jsoi2009]瓶子和燃料 最大公约数
  10. 一张图理清ASP.NET Core启动流程