#1094 : Lost in the City by C solution

 

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

代码实现:

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 int compare(char** s1, int i, int j, char surround[][3])
 5 {
 6     for (int a = i; a<3 + i; a++)
 7         for (int b = j; b<3 + j; b++)
 8         {
 9             if (s1[a][b] != surround[a - i][b - j])
10                 return 0;
11         }
12         
13     return 1;
14 }
15 int main()
16 {
17     int n = 0, m = 0;
18     scanf("%d %d", &n,&m);
19     getchar();
20     char** map = (char**)malloc(sizeof(char)*n);
21     for (int i = 0; i<n; i++)
22     {
23         map[i] = (char*)malloc(sizeof(char)*m);
24         fgets(map[i], m+1, stdin);
25         getchar();
26     }
27     char surround[3][3] = { 0 };
28     for (int i = 0; i<3; i++)
29     {
30         fgets(surround[i], 4, stdin);
31         getchar();
32     }
33     char surround1[3][3] = { 0 };
34     char surround2[3][3] = { 0 };
35     char surround3[3][3] = { 0 };
36     char position = surround[1][1];
37     for (int i = 0; i<3; i++)
38     {
39         for (int j = 0; j<3; j++)
40         {
41             surround1[2 - j][i] = surround[i][j];
42         }
43     }
44     for (int i = 0; i<3; i++)
45     {
46         for (int j = 0; j<3; j++)
47         {
48             surround2[2 - j][i] = surround1[i][j];
49         }
50     }
51     for (int i = 0; i<3; i++)
52     {
53         for (int j = 0; j<3; j++)
54         {
55             surround3[2 - j][i] = surround2[i][j];
56         }
57     }
58     for (int i = 1; i<n - 1; i++)
59     {
60         for (int j = 1; j<m - 1; j++)
61         {
62             
63             if (map[i][j] == position)
64             {
65                 if (compare(map, i - 1, j - 1, surround))
66                 {
67                     printf("%d %d\n", i + 1, j + 1);
68                     continue;
69                 }
70                 if (compare(map, i - 1, j - 1, surround1))
71                 {
72                     printf("%d %d\n", i + 1, j + 1);
73                     continue;
74                 }
75                 if (compare(map, i - 1, j - 1, surround2))
76                 {
77                     printf("%d %d\n", i + 1, j + 1);
78                     continue;
79                 }
80                 if (compare(map, i - 1, j - 1, surround3))
81                 {
82                     printf("%d %d\n", i + 1, j + 1);
83                     continue;
84                 }
85             }
86         }
87     }
88     return 0;
89 }

问题:

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

转载于:https://www.cnblogs.com/Blue-Keroro/p/7767157.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值