程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> hihoCoder

hihoCoder

編輯:關於C++

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









  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved