#1094 : Lost in the City by C solution
描述
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,若知道原因的话还望请留言告知!
#1094 : Lost in the City by C solution的更多相关文章
- hihoCoder #1094 : Lost in the City(枚举,微软苏州校招笔试 12月27日 )
#1094 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He ...
- 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 ...
- #1094 : Lost in the City
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...
- hihoCoder#1094 Lost in the City
原题地址 限时10s,所以不用考虑什么算法了,暴力吧 分别按照3x3视野的四个方向去地图上匹配,把符合的地点标记出来,最后统一按照从上到下,从左到右的顺序输出. 代码: #include <io ...
- 【BZOJ2001】 [Hnoi2010]City 城市建设
BZOJ2001 [Hnoi2010]City 城市建设 Solution 我们考虑一下这个东西怎么求解? 思考无果...... 咦? 好像可以离线cdq,每一次判断一下如果这条边如果不选就直接删除, ...
- WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION
开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...
- bzoj:1687;poj 2434:[Usaco2005 Open]Navigating the City 城市交通
Description A dip in the milk market has forced the cows to move to the city. The only employment av ...
- [Swift]LeetCode807. 保持城市天际线 | Max Increase to Keep City Skyline
In a 2 dimensional array grid, each value grid[i][j]represents the height of a building located ther ...
- [Swift]LeetCode1029. 两地调度 | Two City Scheduling
There are 2N people a company is planning to interview. The cost of flying the i-th person to city A ...
随机推荐
- java面试题整理(1)
1.Equals与==的区别? ==是判断两个变量或者实例是不是指向同一个内存地址 equals是判断两个变量或者实例所指向的内存地址中的值是不是相同 2.Object有哪些公用方法? 方法equal ...
- 深入浅出数据结构C语言版(20)——快速排序
正如上一篇博文所说,今天我们来讨论一下所谓的"高级排序"--快速排序.首先声明,快速排序是一个典型而又"简单"的分治的递归算法. 递归的威力我们在介绍插入排序时 ...
- hadoop超租约报错:
解决方法:修改linux打开文件最大限制Java代码 echo "fs.file-max = 65535" >> /etc/sysctl.conf echo " ...
- 第4章 同步控制 Synchronization ----死锁(DeadLock)
Jeffrey Richter 在他所主持的 Win32 Q&A 专栏(Microsoft Systems Journal,1996/07)中曾经提到过,Windows NT 和 Window ...
- Application->ProcessMessages();
Application.ProcessMessages的用法意义 在循环中加Application.ProcessMessages是可以防止其他控件没响应,举个例子容易明白:假如你的窗体上有两个按 ...
- 打印ASCII码
总时间限制:1000ms内存限制:65536kB 描述 输入一个除空格以外的可见字符(保证在函数scanf中可使用格式说明符%c读入),输出其ASCII码. 输入 一个除空格以外的可见字符. 输出 一 ...
- include 和require的区别
相同点:include和require 都能把另外一个文件包含到当前文件中. 不同点:1.使用include时,当包含的文件不存在时,系统会报出警告级别的错误,程序会继续往下执行. 使用requi ...
- (转)simhash算法原理及实现
simhash是google用来处理海量文本去重的算法. google出品,你懂的. simhash最牛逼的一点就是将一个文档,最后转换成一个64位的字节,暂且称之为特征字,然后判断重复只需要判断他们 ...
- NDK各个版本链接
ndk_r15c (July 2017) Windows 32-bit : https://dl.google.com/android/repository/android-ndk-r15c-wind ...
- fitnesse - 一个简单的例子(slim)
fitnesse - 一个简单的例子(slim) 2017-09-30 目录1 编写测试代码(Fixture code)2 编写wiki page并运行 2.1 新建wikiPage 2.2 运行 ...