只过了38%,求Java解。相对于C++\C,java更容易造成程序运行超时。
importjava.util.Scanner;
publicclassMain {
publicstaticvoidmain(String[] args) {
Scanner in = newScanner(System.in);
intN = in.nextInt();
intM = in.nextInt();
intQ = in.nextInt();
String str = "";
char[][] arrs = newchar[N][M];
for(inti = 0; i < N; i++) {
str = in.next();
arrs[i] = str.toCharArray();
}
while(Q-- > 0) {
intx = in.nextInt();
x = x - 1;
inty = in.nextInt();
y = y - 1;
String p = in.next();
charps = p.charAt(0);
booleanfind = false;
switch(ps) {
case'L':
for(inti = y; i >= 0; i--) {
if(arrs[x][i] == '#') {
find = true;
break;
}
}
break;
case'R':
for(inti = y; i < M; i++) {
if(arrs[x][i] == '#') {
find = true;
break;
}
}
break;
case'U':
for(inti = x; i >= 0; i--) {
if(arrs[i][y] == '#') {
find = true;
break;
}
}
break;
case'D':
for(inti = x; i < N; i++) {
if(arrs[i][y] == '#') {
find = true;
break;
}
}
break;
}
if(find) {
System.out.println("NO");
} else{
System.out.println("YES");
}
}
}
}