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 ;
}

HDU 4121的更多相关文章

  1. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  2. HDU 4121 Xiangqi (算是模拟吧)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4121 题意:中国象棋对决,黑棋只有一个将,红棋有一个帅和不定个车 马 炮冰给定位置,这时当黑棋走,问你黑 ...

  3. HDU 4121 Xiangqi --模拟

    题意: 给一个象棋局势,问黑棋是否死棋了,黑棋只有一个将,红棋可能有2~7个棋,分别可能是车,马,炮以及帅. 解法: 开始写法是对每个棋子,都处理处他能吃的地方,赋为-1,然后判断将能不能走到非-1的 ...

  4. HDU 4121 Xiangqi 我老了?

    Xiangqi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. HDU 4121 Xiangqi

    模拟吧,算是... 被这个题wa到哭,真是什么都不想说了...上代码 #include <iostream> #include <cstring> using namespac ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. 用PyRestful快速构建Tornado下REST APIs 的支持

    一.安装PyRestful库 $ pip install pyrestful 二.使用案例 (一)books_service.py # -*- coding: utf-8 -*- import tor ...

  2. 转: Nodejs概述

    目录 简介 安装与更新 版本管理工具nvm 基本用法 REPL环境 异步操作 全局对象和全局变量 模块化结构 概述 核心模块 自定义模块 fs模块 Stream模式 http模块 实例:搭建一个HTT ...

  3. SIGAR - System Information Gatherer And Reporter

    https://support.hyperic.com/display/SIGAR/Home 收藏一篇: http://www.cnitblog.com/houcy/archive/2012/11/2 ...

  4. ThinkPHP 3.1.2 查询方式的一般使用1

    public function show(){ echo "访问了index模块下的show方法!!"; echo "欢迎你".$_GET['name'].'你 ...

  5. ThinkPHP 3.1.2 模板中的变量

    一.变量输出 (重点) 1.标量输出 2.数组输出 {$name[1]} {$name['k2']} {$name.k1} 3.对象输出 {$name:k} {$name->k} 二.系统变量 ...

  6. [Windows编程] #pragma once 和#ifndef ... #define ... #endif 比较

    C++中防止头文件被多次include 的常见方式有: 1) 用#ifndef ...  #define ... #endif  宏 #ifndef __MYHEADER_H__#define __M ...

  7. Oracle 使用RMAN

    RMAN 数据库备份 特点: . 跳过未使用的数据块 . 备份压缩 . 执行增量备份 . 块级别的恢复 组件: . RMAN命令执行器(RMAN Executable) . 目标数据库(Traget ...

  8. Objective-c @property和@Synthesize

    在Objective-c中,使用@property来标识属性(一般是实例变量).在实现文件中使用@synthesize标识所声明的变量,让系统自动生成设置方法和获取方法. 也就是说@property和 ...

  9. 鼠标放上去图片慢慢变大js 或 变大

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. HDU 1222 Wolf and Rabbit(gcd)

    HDU 1222   Wolf and Rabbit   (最大公约数)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...