HDU 4121

时间:2023-03-09 13:15:43
HDU 4121

http://www.bnuoj.com/v3/problem_show.php?pid=10277

 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std; const int INF = 0x3f3f3f3f;
const int MAXN = ;
const int row = ;
const int col = ; int map[][];
int G_x, G_y, pos_x, pos_y;
bool ans; bool deal(int x, int y){
return (x >= && x <= row && y >= && y <= col);
} bool deal_plus(int x, int y){
if(deal(x, y) && x <= && y >= && y <= ) return true;
return false;
} void init(){
ans = false;
memset(map, , sizeof(map));
} bool shuai(int x, int y){
int i, j;
if(x - < pos_x) return false;
for(i = x - ; i >= pos_x; --i){
if(map[i][y]) break;
}
if(map[i][y] == ) return true;
return false;
} bool ju(int x, int y){
int i, j;
for(i = x + ; i <= pos_x; ++i){
if(x + > pos_x) break;
if(map[i][y]){
if(map[i][y] == ) return true;
else break;
}
}
for(i = x - ; i >= ; --i){
if(x - < ) break;
if(map[i][y]){
if(map[i][y] == ) return true;
else break;
}
}
for(j = y - ; j >= ; --j){
if(y - < ) break;
if(map[x][j]){
if(map[x][j] == ) return true;
else break;
}
}
for(j = y + ; j <= col; ++j){
if(y + > col) break;
if(map[x][j]){
if(map[x][j] == ) return true;
else break;
}
}
return false;
} bool pao(int x, int y){
bool flag = false;
int i, j;
for(i = x + ; i <= pos_x; ++i){
if(x + > pos_x) break;
if(flag){
if(map[i][y] == ) return true;
else break;
} else if(map[i][y]){
flag = true;
}
}
flag = false;
for(i = x - ; i >= ; --i){
if(x - < ) break;
if(flag){
if(map[i][y] == ) return true;
else break;
} else if(map[i][y]){
flag = true;
}
}
flag = false;
for(j = y - ; j >= ; --j){
if(y - < ) break;
if(flag){
if(map[x][j] == ) return true;
else break;
} else if(map[x][j]){
flag = true;
}
}
flag = false;
for(j = y + ; j <= col; ++j){
if(y + > col) break;
if(flag){
if(map[x][j] == ) return true;
else break;
} else if(map[x][j]){
flag = true;
}
}
return false;
} bool ma(int x, int y){
int xx, yy; xx = x + ; yy = y - ;
if(xx == pos_x && yy == pos_y && map[x + ][y] == ) return true; xx = x + ; yy = y + ;
if(xx == pos_x && yy == pos_y && map[x + ][y] == ) return true; xx = x + ; yy = y + ;
if(xx == pos_x && yy == pos_y && map[x][y + ] == ) return true; xx = x - ; yy = y + ;
if(xx == pos_x && yy == pos_y && map[x][y + ] == ) return true; xx = x - ; yy = y + ;
if(xx == pos_x && yy == pos_y && map[x - ][y] == ) return true; xx = x - ; yy = y - ;
if(xx == pos_x && yy == pos_y && map[x - ][y] == ) return true; xx = x - ; yy = y - ;
if(xx == pos_x && yy == pos_y && map[x][y - ] == ) return true; xx = x + ; yy = y - ;
if(xx == pos_x && yy == pos_y && map[x][y - ] == ) return true; return false;
} bool beat(int x, int y){
int i, j;
if(x + > row) return false;
for(i = x + ; i <= row; ++i){
if(map[i][y]) break;
}
if(map[i][y] == ) return true;
return false;
} bool solve(){
int i, j;
for(i = ; i <= row; ++i){
for(j = ; j <= col; ++j){
if(map[i][j] == )
if(shuai(i, j)) return true;
if(map[i][j] == )
if(ju(i, j)) return true;
if(map[i][j] == )
if(pao(i, j)) return true;
if(map[i][j] == )
if(ma(i, j)) return true;
}
}
return false;
} int main(){
int i, j, t;
char cc;
while(cin >> t >> G_x >> G_y){
if(t == && G_x == && G_y == ) break;
init();
map[G_x][G_y] = ;
while(t--){
cin >> cc >> pos_x >> pos_y;
if(cc == 'G'){
map[pos_x][pos_y] = ;
} else if(cc == 'R'){
map[pos_x][pos_y] = ;
} else if(cc == 'C'){
map[pos_x][pos_y] = ;
} else if(cc == 'H'){
map[pos_x][pos_y] = ;
}
}
if(beat(G_x, G_y)){
ans = false;
}
else{
if(deal_plus(G_x - , G_y)){
map[G_x][G_y] = ;
int temp_num = map[G_x - ][G_y];
map[G_x - ][G_y] = ;
pos_x = G_x - ;
pos_y = G_y; if(solve()){
ans = true;
}
else{
printf("NO\n");
continue;
}
map[G_x - ][G_y] = temp_num;
map[G_x][G_y] = ;
}
if(deal_plus(G_x + , G_y)){
map[G_x][G_y] = ;
int temp_num = map[G_x + ][G_y];
map[G_x + ][G_y] = ;
pos_x = G_x + ;
pos_y = G_y; if(solve()){
ans = true;
}
else{
printf("NO\n");
continue;
}
map[G_x + ][G_y] = temp_num;
map[G_x][G_y] = ;
}
if(deal_plus(G_x, G_y - )){
map[G_x][G_y] = ;
int temp_num = map[G_x][G_y - ];
map[G_x][G_y - ] = ;
pos_x = G_x;
pos_y = G_y - ; if(solve()){
ans = true;
}
else{
printf("NO\n");
continue;
}
map[G_x][G_y - ] = temp_num;
map[G_x][G_y] = ;
}
if(deal_plus(G_x, G_y + )){
map[G_x][G_y] = ;
int temp_num = map[G_x][G_y + ];
map[G_x][G_y + ] = ;
pos_x = G_x;
pos_y = G_y + ; if(solve()){
ans = true;
}
else{
printf("NO\n");
continue;
}
map[G_x][G_y + ] = temp_num;
map[G_x][G_y] = ;
}
}
if(ans){
printf("YES\n");
} else{
printf("NO\n");
}
}
return ;
}