#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 ...
随机推荐
- 用reduce实现阶乘计算
def fact(a,b): return a*b from functools import reduce print(reduce(fact,range(1,6))) from functools ...
- UDP接收百万级数据的解决方案
小序 到新公司不久,就接到一个任务:有个发送方,会通过udp发送一些信息,然后服务接收到信息后保存到数据库的一张表A,保存的这些数据在经过一系列处理,处理完成后累积到另一张表B,然后清空处理的表A的数 ...
- Android 之数据存储(sdCard,sharedPreference,sqlite数据库)
sdCard:默认路径在 /storage/sdcard/... Android支持OpenFileOutput和openFileInput方式访问手机存储器上的文件. Context提供了如下两个方 ...
- Jupyter(Python)中无法使用Cache原理分析
前言 最近需要在Jupyter中写一个类库,其中有一个文件实现从数据库中读取空间数据并加载为Feature对象,Feature对象是cartopy封装的geomery列表,能够方便的用于作图等.因为有 ...
- 【个人笔记】《知了堂》node.js简介及创建应用
Node.js是什么? Node.js是建立在谷歌Chrome的JavaScript引擎(V8引擎)的Web应用程序框架.Node.js自带运行时环境可在Javascript脚本的基础上可以解释和执行 ...
- JAVA 一步一步向上爬
Java分为基本数据类型和引用数据类型(类.接口.数组) Integer.MAX_VALUE 浮点型默认为double java采用Unicode char为两个字节 Unicode为每一个字符定制了 ...
- jsp base路径
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- HTML 简述
1.本页超链接 <a href="#t">查看 Chapter 4.</a> <a name="t">Test</a& ...
- HDU-2222文字检索
题目: In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiske ...
- 30分钟快速学习Shell脚本编程
什么是Shell脚本 示例 看个例子吧: #!/bin/sh cd ~ mkdir shell_tut cd shell_tut for ((i=0; i<10; i++)); do touch ...