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

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	private boolean isHere(char[][] hi, char[][] cityMap, int row, int column) {
		if (hi[1][1] != cityMap[row][column])
			return false;
		boolean res = true;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (hi[i][j] != cityMap[row + i - 1][column + j - 1]) {
					return false;
				}
			}
		}
		return true;
	}

	public static void main(String args[]){
		class Pair implements Comparable{
			int x, y;
			Pair(int x,int y){
				this.x = x;
				this.y = y;
			}
			@Override
			public int compareTo(Object o) {
				Pair other = (Pair)o;
				if(this.x==other.x){
					return this.y - other.y;
				}
				// TODO Auto-generated method stub
				return this.x - other.x;
			}
		}

/*		Scanner sc = null;
		try {
			sc = new Scanner(new FileInputStream("D:\\Desktop\\test.txt"));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		Scanner sc = new Scanner(System.in);
		Main main = new Main();
		int row = sc.nextInt();
		int column = sc.nextInt();
		char [][]cityMap = new char[row][column];
		for(int i=0;i<row;i++){
			String str = sc.next();
			for(int j=0;j<column;j++){
				cityMap[i][j]= str.charAt(j);
			}
		}
		char[][] hi1 = new char[3][3];
		char[][] hi2 = new char[3][3];
		char[][] hi3 = new char[3][3];
		char[][] hi4 = new char[3][3];
		for(int i=0;i<3;i++){
			String str = sc.next();
			for(int j=0;j<3;j++){
				char c = str.charAt(j);
				hi1[i][j] = c;
				hi2[2-i][2-j] =c;
				hi3[2-j][i] =c;
				hi4[j][2-i] =c;
			}
		}
		PriorityQueue<Pair> pq = new PriorityQueue<>();
		for(int i=1;i<row-1;i++){
			for(int j=1;j<column-1;j++){
				if(main.isHere(hi1, cityMap, i, j)||main.isHere(hi2, cityMap, i, j)
						||main.isHere(hi3, cityMap, i, j)||main.isHere(hi4, cityMap, i, j)){
					pq.add(new Pair(i,j));
				}
			}
		}
		Pair p = pq.poll();

		while(p!=null){
			System.out.println((p.x+1)+" "+(p.y+1));
			p = pq.poll();
		}
	}
}
时间: 2024-12-10 02:07:23

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

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

微软苏州校招笔试 12月27日

题目1 : 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

20151208,微软12月8日发布12个安全补丁

大家好,我们是微软大中华区安全支持团队. 微软于北京时间2015年12月8日发布了12个新的安全公告,其中8个为严重等级,4个为重要等级,修复了Microsoft Windows.Microsoft Office.Microsoft .NET Framework.Microsoft Lync.Microsoft Silverlight.Internet Explorer和Microsoft Edge软件中的漏洞.其中MS15-124中所修复的漏洞CVE-2015-6164和 MS15-135中所

20141211,微软12月10日发布7个安全补丁

大家好,我们是微软大中华区安全支持团队. 微软于北京时间2014年12月10日发布了7个新的安全公告,其中4个为严重等级,3个为重要等级,共修复Microsoft Windows.Internet Explorer (IE).Office 和 Exchange 中的24个漏洞.建议优先部署MS14-080 和MS14-081. MS14-080 | Internet Explorer 的累积安全更新 (3008923) 此安全更新可解决 Internet Explorer 中 14 个秘密报告的

2015微软创新杯Imaginecup大赛报名进行中(报名截止2014年12月31日23:59)

CSDN高校俱乐部与微软官方合作,2015微软创新杯大赛中国区官网落户CSDN高校俱乐部:http://student.csdn.net/mcs/imaginecup2015 在微软官方设置创新杯中国区奖项之外,CSDN高校俱乐部每个竞赛项目特设一等奖.二等奖.三等奖及纪念奖若干名. CSDN高校俱乐部特别奖(获奖者需在高校俱乐部进行过报名备案):详情-> 1. 一等奖(三支团队): 每个竞赛项目一等奖一名,每支团队获得奖金2,000元人民币,团队成员每人尊享2015 CSDN VIP年卡会员:

20151208,微软12月8日公布12个安全补丁

大家好,我们是微软大中华区安全支持团队. 微软于北京时间2015年12月8日公布了12个新的安全公告.当中8个为严重等级,4个为重要等级,修复了Microsoft Windows.Microsoft Office.Microsoft .NET Framework.Microsoft Lync.Microsoft Silverlight.Internet Explorer和Microsoft Edge软件中的漏洞.当中MS15-124中所修复的漏洞CVE-2015-6164和 MS15-135中所

微软将于12月3日再次尝试把HoloLens送入太空

微软再次尝试将HoloLens送入太空.两部增强现实设备原型现在已经列入国际空间站补给火箭内部的货物项目,火箭将于12月3日发射. 在六月份,六合资料和美国航空航天局曾尝试将两部HoloLens设备放入SpaceX公司的火箭向国际空间站运送,但是升空后不久就爆炸了.这一次,HoloLens设备将搭载由Orbital Sciences打造的火箭.我们希望这一次能够成功. 美国航空航天局希望宇航员登上国际空间站,然后在一个名为Sidekick的计划中测试HoloLens,该计划旨在让地球上的人们可以

SQL点滴6—“微软不认识闰年2月29日”&amp;字符&quot;N&quot;的作用

原文:SQL点滴6-"微软不认识闰年2月29日"&字符"N"的作用 http://www.cnbeta.com/articles/50580.htm这个网页新闻中报告许多微软软件不能识别闰年的2月29号 ,其中就包含SQL Server 2008,本人就在自己的SQL Server 2008中写了几个语句试验,这几个语句显示能得到2月29号这一天,不知道照这则新闻所说在这一天安装软件会不会导致错误. select DATEADD(DD,1,'28/Feb/2

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