#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 ...
随机推荐
- bind9的一些配置
/etc/bind/named.conf.options:options { listen-on port 53 { any; }; // 监听在主机的53端口上.any代表监听所有的主机 direc ...
- 常见注入手法第一讲EIP寄存器注入
常见注入手法第一讲EIP寄存器注入 博客园IBinary原创 博客连接:http://www.cnblogs.com/iBinary/ 转载请注明出处,谢谢 鉴于注入手法太多,所以这里自己整理一下, ...
- Java并发之线程间的协作
上篇文章我们介绍了synchronized关键字,使用它可以有效的解决我们多线程所带来的一些常见问题.例如:竞态条件,内存可见性等.并且,我们也说明了该关键字主要是一个加锁和释放锁的集成,所有为能获得 ...
- JVM菜鸟进阶高手之路二(JVM的重要性,Xmn是跟请求量有关。)
转载请注明原创出处,谢谢! 今天看群聊jvm,通常会问ygc合适吗? 阿飞总结,可能需要2个维度,1.单位时间执行次数,2.执行时间 ps -p pid -o etime 查看下进程的运行时间, 17 ...
- 一篇搞定微信分享和line分享
前言 在h5的页面开发中,分享是不可或缺的一部分,对于一些传播性比较强的页面,活动页之类的,分享功能极为重要.例如,京东等电商年末时会有一系列的总结h5在微信中传播,就不得不提到微信的分享机制. 微信 ...
- 【前端】深入浅出Javascript中的数值转换
由于Javascript是一门弱类型的语言,在我们的代码中无时无刻不在发生着类型转换,所以了解Javascript中的类型转换对于了解我们认识Javascript的运行原理至关重要. 本文主要从数值转 ...
- 关于修改extmail附件大小限制的位置
一.修改extmail的webmail.cf文件, SYS_MESSAGE_SIZE_LIMIT = 5242880 注意:以位为单位为5M字节. SYS_MESSAGE_SIZE_LIMIT = x ...
- 【京东个人中心】——Nodejs/Ajax/HTML5/Mysql爬坑之注册与登录监听
一.引言 在数据库和静态页面都创建好之后,下面就该接着完成后台Node.js监听注册和登录的部分了.这个部分主要使用的技术是:Node.js的Express框架和ajax异步请求.登录和注册的代码实现 ...
- 学习札记 ----wind7下如何安装SqlServer数据库
1.控制面板 ---找到程序和功能选项 如下图所示: 2.打开程序和功能后进入如下图所示的界面,点击打开或关闭window功能. 3.启动window7自带的IIS功能.如下图所示: 4.如上动作准备 ...
- JQuery上传插件Uploadify详解及其中文按钮解决方案 .
Uploadify有一个参数是 buttonText 这个无论你怎么改都不支持中文,因为插件在js里用了一个转码方法把这个参数的值转过码了,解码的地方在那个swf文件里,看不到代码,所以这条路不行. ...