hihoCoder#1094 Lost in the City

原题地址

限时10s,所以不用考虑什么算法了,暴力吧

分别按照3x3视野的四个方向去地图上匹配,把符合的地点标记出来,最后统一按照从上到下,从左到右的顺序输出。

代码:

 1 #include <iostream>
 2
 3 using namespace std;
 4
 5 #define MAP_SIZE 250
 6
 7 bool match(char map[MAP_SIZE][MAP_SIZE], char sight[3][3], int r, int c) {
 8   for (int i = 0; i < 3; i++)
 9     for (int j = 0; j < 3; j++)
10       if (map[r + i][c + j] != sight[i][j])
11         return false;
12   return true;
13 }
14
15 void find(char map[MAP_SIZE][MAP_SIZE], char sight[3][3], char res[MAP_SIZE][MAP_SIZE], int N, int M) {
16   for (int i = 0; i < N - 2; i++) {
17     for (int j = 0; j < M - 2; j++) {
18       if (match(map, sight, i, j))
19         res[i + 1][j + 1] = 1;
20     }
21   }
22 }
23
24 void rotate(char sight[3][3]) {
25   for (int i = 0; i < 2; i++)
26     for (int j = 0; j < 2; j++)
27       swap(sight[i][j], sight[2 - j][2 - i]);
28   for (int i = 0; i < 3; i++)
29     swap(sight[0][i], sight[2][i]);
30 }
31
32 int main() {
33   int N, M;
34   char map[MAP_SIZE][MAP_SIZE];
35   char res[MAP_SIZE][MAP_SIZE];
36   char sight[3][3];
37
38   cin >> N >> M;
39   for (int i = 0; i < N; i++)
40     for (int j = 0; j < M; j++)
41       cin >> map[i][j];
42
43   for (int i = 0; i < 3; i++)
44     for (int j = 0; j < 3; j++)
45       cin >> sight[i][j];
46
47   memset(res, 0, MAP_SIZE * MAP_SIZE * sizeof(char));
48
49   for (int i = 0; i < 4; i++) {
50     find(map, sight, res, N, M);
51     rotate(sight);
52   }
53
54   for (int i = 1; i < N - 1; i++)
55     for (int j = 1; j < M - 1; j++)
56       if (res[i][j])
57         cout << i + 1 << " " << j + 1 << endl;
58
59   return 0;
60 }
时间: 2024-10-20 08:26:40

hihoCoder#1094 Lost in the City的相关文章

hihoCoder - 1094 - Lost in the City (暴力枚举!!)

#1094 : Lost in the City 时间限制: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 gri

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 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 gri

[HiHoCoder]#1094 : Lost in the City 微软苏州校招笔试 12月27日

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

hihoCoder#1094

刚开始学习C语言,准备在做hiho的题目的过程中来学习,在此进行记录,如果代码中有错误或者不当的地方还请指正. 时间限制: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

hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

#1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people could not tolerate the pollution in the city any more, and started a long-lasting protest. Eventually, the municipal government made up its mind to deal w

hihoCoder太阁最新面经算法竞赛15

Link: http://hihocoder.com/contest/hihointerview24 题目1 : Boarding Passes 时间限制:10000ms 单点时限:1000ms 内存限制:256MB   描述 Long long ago you took a crazy trip around the world. You can not remember which cities did you start and finish the trip.  Luckily you

City Upgrades

City Upgrades Time limit: 1000 msMemory limit: 128 MB There are N cities placed in a line. For each city ii you know its coodinate x??. You can upgrade exactly K of these cities. Your goal is to choose what cities to upgrade in a way the minimizes th

dutacm.club 1094: 等差区间(RMQ区间最大、最小值,区间GCD)

1094: 等差区间 Time Limit:5000/3000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)Total Submissions:655   Accepted:54 [Submit][Status][Discuss] Description 已知一个长度为 n 的数组 a[1],a[2],-,a[n],我们进行 q 次询问,每次询问区间 a[l],a[l+1],-,a[r?1],a[r] ,数字从小到大

[hihoCoder#1381]Little Y&#39;s Tree

[hihoCoder#1381]Little Y's Tree 试题描述 小Y有一棵n个节点的树,每条边都有正的边权. 小J有q个询问,每次小J会删掉这个树中的k条边,这棵树被分成k+1个连通块.小J想知道每个连通块中最远点对距离的和. 这里的询问是互相独立的,即每次都是在小Y的原树上进行操作. 输入 第一行一个整数n,接下来n-1行每行三个整数u,v,w,其中第i行表示第i条边边权为wi,连接了ui,vi两点. 接下来一行一个整数q,表示有q组询问. 对于每组询问,第一行一个正整数k,接下来一