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 ;
}
HDU 4121的更多相关文章
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- HDU 4121 Xiangqi (算是模拟吧)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4121 题意:中国象棋对决,黑棋只有一个将,红棋有一个帅和不定个车 马 炮冰给定位置,这时当黑棋走,问你黑 ...
- HDU 4121 Xiangqi --模拟
题意: 给一个象棋局势,问黑棋是否死棋了,黑棋只有一个将,红棋可能有2~7个棋,分别可能是车,马,炮以及帅. 解法: 开始写法是对每个棋子,都处理处他能吃的地方,赋为-1,然后判断将能不能走到非-1的 ...
- HDU 4121 Xiangqi 我老了?
Xiangqi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 4121 Xiangqi
模拟吧,算是... 被这个题wa到哭,真是什么都不想说了...上代码 #include <iostream> #include <cstring> using namespac ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- Oracle的大数据类型,BIG DATA TYPE
1.CLOB 字符LOB类型,主要用于存储大型英文字符 2.NCLOB 国际语言字符LOB类型,主要用于存储大型非英文字符 3.BLOB 二进制LOB类型,主要用于存储二进制数据 4.BFILE 二进 ...
- codeforces 557D. Vitaly and Cycle 二分图染色
题目链接 n个点, m条边, 问最少加几条边可以出现一个奇环, 在这种情况下, 有多少种加边的方式. 具体看代码解释 #include<bits/stdc++.h> using names ...
- [LeetCode]题解(python):069-Sqrt(x)
题目来源: https://leetcode.com/problems/sqrtx/ 题意分析: 实现一个整型的开根. 题目思路: 利用牛顿迭代法可以求解.首先讲数据类型转成浮点数,然后选取初始值为n ...
- IOS 使用IOS6苹果地图
IOS应用程序中使用Map Kit API开发地图应用程序.其核心是MKMapView类的使用.我们可以设置地图显示方式,控制地图,可以在地图上添加标注. 1.显示地图 在Map Kit API中显示 ...
- eclipse设置web项目发布到tomcat根目录下
如果已经将项目绑定到服务器了,那就先删除服务器. 重新添加项目进服务器,双击 修改下面Server Locations到tomcat目录下 顺带可以修改下右上角的超时设置 再点击下方 这样就可以了.
- 深入剖析哪些服务是Oracle 11g必须开启的
这篇文章主要介绍了哪些服务是Oracle 11g必须开启的以及这些服务的详细介绍,需要的朋友可以参考下 成功安装Oracle 11g数据库后,你会发现自己电脑运行速度会变慢,配置较低的电脑甚至出现 ...
- perl5 第三章 操作符
第三章 操作符 by flamephoenix 一.算术操作符二.整数比较操作符三.字符串比较操作符四.逻辑操作符五.位操作符六.赋值操作符七.自增自减操作符八.字符串联结和重复操作符九.逗号操作符十 ...
- HDU 2138 How many prime numbers
米勒罗宾素数测试: /* if n < 1,373,653, it is enough to test a = 2 and 3. if n < 9,080,191, it is enoug ...
- Flex 百度地图API使用
今天想看一下Flex中关于地图方面的使用,刚开始看了google map api, 感觉用起来挺麻烦,关键是英文不好,文档读起来费劲,还有密钥神马的~ 那我就试验一下百度地图的接口,文档是中文的. 首 ...
- [爬虫]通过url获取连接地址中的数据
1. 要想获取指定连接的数据,那么就得使用HtmlDocument对象,要想使用HtmlDocument对象就必需引用using HtmlAgilityPack; 2. 详细步骤如下: 步骤一 ...