#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.
- 8 8
- 样例输出
-
- 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 ...
随机推荐
- WEB项目的部署结构
tomcat/webapps目录是用来存放Java项目的.每一个文件夹都是一个项目,默认这个目录下已经有了四个项目,都是tomcat自带的. 其中ROOT就是我们测试Tomcat时访问的Tomcat的 ...
- oracle "记录被另一个用户锁定"
出现的原因是有人对某一条数据进行了修改,oracle会通过这个事务记住这条数据,若修改的人没有进行提交或进行回滚记录,oracle是不允许对这条数据在此进行修改的,在这种情况下你要进行修改数据,则会被 ...
- CSS 基本样式
1.CSS 背景: css 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果 属性 描述 background-attachment 背景图像是否固定或者随着页面的其余部分滚动 backgr ...
- Unity 3D 之贪吃蛇 Text 心得 & Audio
当我们需要在游戏街面上增加文本时, 我们就需要用到Text 组件 注意: 当文本的长度或者宽度不够时,字体将无法显示. 因为是面对组件编程,所以每一个组件的component都可以同过GetCompo ...
- [js高手之路] 设计模式系列课程 - 迭代器(1)
迭代器是指通过一种形式依次遍历数组,对象,或者类数组结构中的每个元素. 常见的有jquery中的each方法, ES5自带的forEach方法. 下面我们就来自定义一个类似jquery或者ES5的迭代 ...
- angular之表单验证与ngMessages
刚接触angular1.x很多经常用到的ngMessages的地方,这里顺便记一下,效果如下图: 如果引用了angular-messages.js报如下错误,说明你的angular.js和angula ...
- 入坑IT都快十年了
一起帮的开发直播已经告一段落:一是主体的功能差不多都实现了,二是用到的架构技术都展示得差不多了.以后就算继续开发,也应该都是一些“技术上”重复的工作而已.整个直播过程耗时近半年,SVN提交1062次, ...
- [js高手之路] html5 canvas系列教程 - 线条样式(lineWidth,lineCap,lineJoin,setLineDash)
上文,写完弧度与贝塞尔曲线[js高手之路] html5 canvas系列教程 - arcTo(弧度与二次,三次贝塞尔曲线以及在线工具),本文主要是关于线条的样式设置 lineWidth: 设置线条的宽 ...
- TCP/IP(五)传输层(TCP的三次握手和四次挥手)
前言 这一篇我将介绍的是大家面试经常被会问到的,三次握手四次挥手的过程.以前我听到这个是什么意思呀?听的我一脸蒙逼,但是学习之后就原来就那么回事! 一.运输层概述 1.1.运输层简介 这一层的功能也挺 ...
- Disharmony Trees 树状数组
Disharmony Trees Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...