时间限制: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.
样例输入
import java.util.*;
public class Main {
static HashSet<Postion> retList = new HashSet<Main.Postion>();
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int m = cin.nextInt();
ArrayList<String> map = new ArrayList<String>();
ArrayList<String> me = new ArrayList<String>();
for (int i = 0; i < n; ++i) {
map.add(cin.next());
}
me.add(cin.next());
me.add(cin.next());
me.add(cin.next());
for (int i = 0; i < 4; ++i) {
getPosition(map, me);
me = transfer(me);
// output(me);
}
if (retList.size() > 0) {
Postion[] ps = new Postion[retList.size()];
retList.toArray(ps);
Arrays.sort(ps, new Comparator<Postion>() {
public int compare(Postion o1, Postion o2) {
return o1.i != o2.i ? o1.i - o2.i : o1.j - o2.j;
}
});
for (Postion p : ps) {
System.out.println(p.i + " " + p.j);
}
}
}
static class Postion {
int i;
int j;
public Postion(int i, int j) {
this.i = i;
this.j = j;
}
/*
* public int compareTo(Postion o) { return i != o.i ? i - o.i : j -
* o.j; }
*/
public boolean equals(Object o) {
if (o instanceof Postion) {
Postion o2 = (Postion) o;
Postion o1 = this;
return o1.i == o2.i && o1.j == o2.j;
}
return false;
}
public int hashCode() {
return (i << 4) + j;
}
}
static void output(ArrayList<String> list) {
for (String s : list) {
System.out.println(s);
}
}
static ArrayList<String> transfer(ArrayList<String> me) {
ArrayList<String> ret = new ArrayList<String>();
byte[][] a = new byte[3][3];
for (int i = 0; i < 3; ++i) {
byte[] t = me.get(i).getBytes();
for (int j = 0; j < 3; ++j) {
a[j][2 - i] = t[j];
}
}
for (int i = 0; i < 3; ++i) {
ret.add(new String(a[i]));
}
return ret;
}
static int[] getPosition(ArrayList<String> map, ArrayList<String> me) {
for (int i = 0, len = map.size() - 2; i < len; ++i) {
String line = map.get(i);
int index = 0;
while (line.indexOf(me.get(0), index) != -1) {
if (map.get(i + 1).indexOf(me.get(1), index) == line.indexOf(me.get(0), index)
&& map.get(i + 2).indexOf(me.get(2), index) == line.indexOf(me.get(0), index)) {
retList.add(new Postion(i + 2, line.indexOf(me.get(0), index) + 2));
}
index++;
}
}
return null;
}
}
/*
9 9
asdasdasd
asdasdasd
asdasdasd
asdasdasd
asdasdasd
asdasdasd
asdasdasd
asdasdasd
asdasdasd
asd
asd
asd
*/