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

枚举得让我醉了。。

思路:本题是去求little hi大致在哪里,,可能有多个地点,,然后枚举。。模拟过去。。

AC代码(略挫。。):

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; 

char map[205][205];
char sur[5][5];
char sur1[5][5];
char sur2[5][5];
char sur3[5][5];

void change(char sur[][5])		//将字符串向右转90度
{
	char tmp[5][5];
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			tmp[i][j] = sur[i][j];
	for(int i=0; i<3; i++)
		sur[i][2] = tmp[0][i];
	for(int i=0; i<3; i++)
		sur[i][1] = tmp[1][i];
	for(int i=0; i<3; i++)
		sur[i][0] = tmp[2][i];
}

void create(char sur[][5])		//求出将字符串转90,180,270之后的情况
{
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			sur1[i][j] = sur[i][j];
	change(sur1);
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			sur2[i][j] = sur1[i][j];
	change(sur2);
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			sur3[i][j] = sur2[i][j];
	change(sur3);
}

int judge(char map[][205], int x, int y, char sur[][5])		//判断是否匹配
{
	if(map[x-1][y-1] != sur[0][0] || map[x-1][y] != sur[0][1] ||  map[x-1][y+1] != sur[0][2]
		|| map[x][y-1] != sur[1][0] || map[x][y] != sur[1][1] || map[x][y+1] != sur[1][2]
		|| map[x+1][y-1] != sur[2][0] || map[x+1][y] != sur[2][1] || map[x+1][y+1] != sur[2][2]) return 0;
	return 1;
}

int main()
{
	int n, m;
	while(scanf("%d %d", &n, &m) != EOF)
	{
		char surr[11] = "";
		for(int i=0; i<n; i++)
			scanf("%s", map[i]);

		for(int i=0; i<3; i++)
			scanf("%s", sur[i]);
		char center = sur[1][1];
		create(sur);
		for(int i=1; i<=n; i++)
			for(int j=1; j<=m; j++)
			if(center == map[i][j])
			{
				if(judge(map, i, j, sur) || judge(map, i, j, sur1)
				 || judge(map, i, j, sur2) || judge(map, i, j, sur3))
				 	printf("%d %d\n", i+1, j+1);
			}
	}
	return 0;
}
时间: 2024-10-06 02:44:23

hihoCoder - 1094 - Lost in the City (暴力枚举!!)的相关文章

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

原题地址 限时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

[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 #1179 : 永恒游戏 (暴力枚举)

题意:给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF,否则输出最多能玩几次. 思路:暴力枚举每个可以玩的点,假如可以玩无限次,且当前状态为Z(指所有点的石头数的序列作为一个状态),那么在玩了多次之后,一定会造成循环,也就是说,玩几次之后,每个点的石子数和初始的石子数一模一样,这样子我再重复之前是怎么玩的就可以无限玩了.但是由于有200个点,所以玩一次就去

HDU 4081 Qin Shi Huang&#39;s National Road System(最小生成树+暴力枚举边)

题目大意:给你1000个点,每个点上有一个数目代表这个城市有多少人,让你把这N个点构成一颗生成树,你可以删除其中的任意一条边.让你求出一个比例A/B是的这个比例最大,A表示你删除那条边上两个城市的人口数之和,B表示的是去掉这条变这可生成树上其他的边的总长度. 解体思路:先求出来最小生成树,然后暴力枚举生成树的边,B=总数-这条边的长度.A = 将这条连断开之后左右集合中权值最大的两个数的和. 这样保证了B最小的情况下,去找最大的A,所以是可行的解.生成树的同时建边,然后dfs找最大值. PS:这

hdu5616 暴力枚举

2017-08-25 20:08:54 writer:pprp 题目简述: ? HDU 5616? n个砝码,可以放在天平左右两侧或不放? m次询问,每次询问是否可以测出给定重量? 1 ≤ n ≤ 20? 1 ≤ m ≤ 100 这道题采用枚举的思路的话实现起来还是有点困难的, 要实现的功能是对每个砝码进行处理,加到左边, 加到右边,或者是不加 看了大神的代码,感觉很巧妙, 设置了两个标记数组 vis1[2005], vis2[2005] 一个vis1用来记录当前已经可以实现的重量 另一个vis

hdu4282A very hard mathematic problem 暴力枚举

//给出k //找x,y,z使得x^z+y^z+x*y*z = k //x,y,z都为正整数x<y,z>1问有多少种方法 //当z = 2时,可以看到左边是一个完全平方 //而当z>=3时,可以暴力枚举x,y //由于k<2^31所以x<2^(31/3)枚举复杂度可以过 #include<cstdio> #include<cstring> #include<iostream> #include<cmath> using name

hdu 5247 找连续数【暴力枚举】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5247 分析:这道题是2015百度之星初赛1的2题,当时没看这道题 是队友看的,比完以后也做了一下,思路大体都是一样的,就是 暴力枚举,因为k<=1000,那么我们可以每一点x为起点跑[x,x+999] 这段区间,把每得到一段连续的子区间[x,?],则num[len]++(len=size([x,?])); 这样就可以了,最后num数组里就是对应的答案 献上代码: #include<stdio.h&

HDU 4770 Lights Against Dudely 暴力枚举+dfs

又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ czy Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1360    Accepted Subm