#1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)
来源:互联网 发布:帝国cms 手册 编辑:程序博客网 时间:2024/06/05 02:07
1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)
描述
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.Scanner;import java.util.Stack;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); char arr[][] = new char[N][M]; char a[][] = new char[3][3]; String str = null; sc.nextLine(); for(int i = 0; i < arr.length; i++) { str = sc.nextLine(); char chrArr[] = str.toCharArray(); for(int j = 0; j < N; j++) arr[i][j] = chrArr[j]; } // sc.nextLine(); for(int i = 0; i < 3; i++) { str = sc.nextLine(); char chrArr[] = str.toCharArray(); for(int j = 0; j < 3; j++) a[i][j] = chrArr[j]; } //north new Main().compareMatrix(arr, a, N, M); //south a = new Main().rotateMatrix(a); a = new Main().rotateMatrix(a); new Main().compareMatrix(arr, a, N, M); //west a = new Main().rotateMatrix(a); new Main().compareMatrix(arr, a, N, M); //east a = new Main().rotateMatrix(a); a = new Main().rotateMatrix(a); new Main().compareMatrix(arr, a, N, M); } //针对N*N类型矩阵旋转90度 char[][] rotateMatrix(char a[][]) { int row = a.length; char arr[][] = new char[row][row]; int col = row - 1; int count = 0; for(int i = 0; i < row; i++) { int num = 0; for(int j = 0; j < row; j++) { arr[num++][col - count] = a[i][j]; } count++; } return arr; } void compareMatrix(char arr[][], char a[][], int N, int M) { for(int i = 0; i + 2 < N; i++) { for(int j = 0; j + 2 < M; j++) { boolean flag = true; for(int ik = 0; ik < 3; ik++) { for(int jk = 0; jk < 3; jk++) { if(a[ik][jk] != arr[i + ik][j + jk]) { flag = false; break; } } } if(flag == false) continue; else { int tempI = i + 2; int tempJ = j + 2; System.out.println(tempI + "" + tempJ); //return; } } } }}
- #1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)
- #1094 : Lost in the City
- #1094 Lost in the City
- #1094 : Lost in the City
- Lost in the City
- Lost in the City
- hihocoder#1094 Lost in the City
- hihoCoder 1094 Lost in the City
- HIHOCODER#1094 : Lost in the City
- hihocoder-#1094 : Lost in the City
- hihoCoder题库1094Lost in the City
- hihocoder #1094 : Lost in the City
- 【hihocoder】#1094 : Lost in the City
- hiho #1094 : Lost in the City
- hihoCoder #1094 : Lost in the City
- hihocoder 1094 : Lost in the City
- hihocoder #1094 : Lost in the City
- hihocoder:Lost in the City
- Java遇到List<?>判断处理
- 安卓6.0权限申请封装
- 调试经验-java.sql.SQLException: No suitable driver found for jdbc:derby:iDB
- Spring Boot使用redis实现数据缓存
- Java 二维数组的初始化
- #1094 : Lost in the City(测试用例正确,但提交显示WA,求发现我程序错误)
- 如何写出高质量的技术博客
- Javascript面向对象(三)——原型继承
- 免费馅饼——动态规划
- 【LeetCode】30. Substring with Concatenation of All Words
- 4.15
- Qt QTextEdit设置行间距和段间距
- LabVIEW创建二维数组及计算数组平方和
- 2017 网易 [编程题] 魔力手环