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

  1. //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <climits>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <stack>
  8. #include <vector>
  9. #include <algorithm>
  10. #define ll long long
  11. using namespace std;
  12.  
  13. const int INF = 0x3f3f3f3f;
  14. const int MAXN = ;
  15. const int row = ;
  16. const int col = ;
  17.  
  18. int map[][];
  19. int G_x, G_y, pos_x, pos_y;
  20. bool ans;
  21.  
  22. bool deal(int x, int y){
  23. return (x >= && x <= row && y >= && y <= col);
  24. }
  25.  
  26. bool deal_plus(int x, int y){
  27. if(deal(x, y) && x <= && y >= && y <= ) return true;
  28. return false;
  29. }
  30.  
  31. void init(){
  32. ans = false;
  33. memset(map, , sizeof(map));
  34. }
  35.  
  36. bool shuai(int x, int y){
  37. int i, j;
  38. if(x - < pos_x) return false;
  39. for(i = x - ; i >= pos_x; --i){
  40. if(map[i][y]) break;
  41. }
  42. if(map[i][y] == ) return true;
  43. return false;
  44. }
  45.  
  46. bool ju(int x, int y){
  47. int i, j;
  48. for(i = x + ; i <= pos_x; ++i){
  49. if(x + > pos_x) break;
  50. if(map[i][y]){
  51. if(map[i][y] == ) return true;
  52. else break;
  53. }
  54. }
  55. for(i = x - ; i >= ; --i){
  56. if(x - < ) break;
  57. if(map[i][y]){
  58. if(map[i][y] == ) return true;
  59. else break;
  60. }
  61. }
  62. for(j = y - ; j >= ; --j){
  63. if(y - < ) break;
  64. if(map[x][j]){
  65. if(map[x][j] == ) return true;
  66. else break;
  67. }
  68. }
  69. for(j = y + ; j <= col; ++j){
  70. if(y + > col) break;
  71. if(map[x][j]){
  72. if(map[x][j] == ) return true;
  73. else break;
  74. }
  75. }
  76. return false;
  77. }
  78.  
  79. bool pao(int x, int y){
  80. bool flag = false;
  81. int i, j;
  82. for(i = x + ; i <= pos_x; ++i){
  83. if(x + > pos_x) break;
  84. if(flag){
  85. if(map[i][y] == ) return true;
  86. else break;
  87. } else if(map[i][y]){
  88. flag = true;
  89. }
  90. }
  91. flag = false;
  92. for(i = x - ; i >= ; --i){
  93. if(x - < ) break;
  94. if(flag){
  95. if(map[i][y] == ) return true;
  96. else break;
  97. } else if(map[i][y]){
  98. flag = true;
  99. }
  100. }
  101. flag = false;
  102. for(j = y - ; j >= ; --j){
  103. if(y - < ) break;
  104. if(flag){
  105. if(map[x][j] == ) return true;
  106. else break;
  107. } else if(map[x][j]){
  108. flag = true;
  109. }
  110. }
  111. flag = false;
  112. for(j = y + ; j <= col; ++j){
  113. if(y + > col) break;
  114. if(flag){
  115. if(map[x][j] == ) return true;
  116. else break;
  117. } else if(map[x][j]){
  118. flag = true;
  119. }
  120. }
  121. return false;
  122. }
  123.  
  124. bool ma(int x, int y){
  125. int xx, yy;
  126.  
  127. xx = x + ; yy = y - ;
  128. if(xx == pos_x && yy == pos_y && map[x + ][y] == ) return true;
  129.  
  130. xx = x + ; yy = y + ;
  131. if(xx == pos_x && yy == pos_y && map[x + ][y] == ) return true;
  132.  
  133. xx = x + ; yy = y + ;
  134. if(xx == pos_x && yy == pos_y && map[x][y + ] == ) return true;
  135.  
  136. xx = x - ; yy = y + ;
  137. if(xx == pos_x && yy == pos_y && map[x][y + ] == ) return true;
  138.  
  139. xx = x - ; yy = y + ;
  140. if(xx == pos_x && yy == pos_y && map[x - ][y] == ) return true;
  141.  
  142. xx = x - ; yy = y - ;
  143. if(xx == pos_x && yy == pos_y && map[x - ][y] == ) return true;
  144.  
  145. xx = x - ; yy = y - ;
  146. if(xx == pos_x && yy == pos_y && map[x][y - ] == ) return true;
  147.  
  148. xx = x + ; yy = y - ;
  149. if(xx == pos_x && yy == pos_y && map[x][y - ] == ) return true;
  150.  
  151. return false;
  152. }
  153.  
  154. bool beat(int x, int y){
  155. int i, j;
  156. if(x + > row) return false;
  157. for(i = x + ; i <= row; ++i){
  158. if(map[i][y]) break;
  159. }
  160. if(map[i][y] == ) return true;
  161. return false;
  162. }
  163.  
  164. bool solve(){
  165. int i, j;
  166. for(i = ; i <= row; ++i){
  167. for(j = ; j <= col; ++j){
  168. if(map[i][j] == )
  169. if(shuai(i, j)) return true;
  170. if(map[i][j] == )
  171. if(ju(i, j)) return true;
  172. if(map[i][j] == )
  173. if(pao(i, j)) return true;
  174. if(map[i][j] == )
  175. if(ma(i, j)) return true;
  176. }
  177. }
  178. return false;
  179. }
  180.  
  181. int main(){
  182. int i, j, t;
  183. char cc;
  184. while(cin >> t >> G_x >> G_y){
  185. if(t == && G_x == && G_y == ) break;
  186. init();
  187. map[G_x][G_y] = ;
  188. while(t--){
  189. cin >> cc >> pos_x >> pos_y;
  190. if(cc == 'G'){
  191. map[pos_x][pos_y] = ;
  192. } else if(cc == 'R'){
  193. map[pos_x][pos_y] = ;
  194. } else if(cc == 'C'){
  195. map[pos_x][pos_y] = ;
  196. } else if(cc == 'H'){
  197. map[pos_x][pos_y] = ;
  198. }
  199. }
  200. if(beat(G_x, G_y)){
  201. ans = false;
  202. }
  203. else{
  204. if(deal_plus(G_x - , G_y)){
  205. map[G_x][G_y] = ;
  206. int temp_num = map[G_x - ][G_y];
  207. map[G_x - ][G_y] = ;
  208. pos_x = G_x - ;
  209. pos_y = G_y;
  210.  
  211. if(solve()){
  212. ans = true;
  213. }
  214. else{
  215. printf("NO\n");
  216. continue;
  217. }
  218. map[G_x - ][G_y] = temp_num;
  219. map[G_x][G_y] = ;
  220. }
  221. if(deal_plus(G_x + , G_y)){
  222. map[G_x][G_y] = ;
  223. int temp_num = map[G_x + ][G_y];
  224. map[G_x + ][G_y] = ;
  225. pos_x = G_x + ;
  226. pos_y = G_y;
  227.  
  228. if(solve()){
  229. ans = true;
  230. }
  231. else{
  232. printf("NO\n");
  233. continue;
  234. }
  235. map[G_x + ][G_y] = temp_num;
  236. map[G_x][G_y] = ;
  237. }
  238. if(deal_plus(G_x, G_y - )){
  239. map[G_x][G_y] = ;
  240. int temp_num = map[G_x][G_y - ];
  241. map[G_x][G_y - ] = ;
  242. pos_x = G_x;
  243. pos_y = G_y - ;
  244.  
  245. if(solve()){
  246. ans = true;
  247. }
  248. else{
  249. printf("NO\n");
  250. continue;
  251. }
  252. map[G_x][G_y - ] = temp_num;
  253. map[G_x][G_y] = ;
  254. }
  255. if(deal_plus(G_x, G_y + )){
  256. map[G_x][G_y] = ;
  257. int temp_num = map[G_x][G_y + ];
  258. map[G_x][G_y + ] = ;
  259. pos_x = G_x;
  260. pos_y = G_y + ;
  261.  
  262. if(solve()){
  263. ans = true;
  264. }
  265. else{
  266. printf("NO\n");
  267. continue;
  268. }
  269. map[G_x][G_y + ] = temp_num;
  270. map[G_x][G_y] = ;
  271. }
  272. }
  273. if(ans){
  274. printf("YES\n");
  275. } else{
  276. printf("NO\n");
  277. }
  278. }
  279. return ;
  280. }

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. 记NOIP分数出来前

    咩~成绩还没有出来呢!但是拿到了每个人的程序,还有一堆民间的数据.我测了好多不同的数据,基本上D1T1,D2T1,D2T2的都是暴力解决掉的,没有什么问题,唯一就是D1T2的link那一题,写的时候2 ...

  2. java学习之jdbc的封装

    jdbc是连接数据库必不可少的工具,但每次连接都要重新写一遍太麻烦了,也不利于代码的可读性,这里做一个工具类进行封装. package com.gh; import java.sql.Connecti ...

  3. hdoj 3549 Flow Problem(最大网络流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 思路分析:该问题为裸的最大网络流问题,数据量不大,使用EdmondsKarp算法求解即可:需要注 ...

  4. 数学之路-python计算实战(16)-机器视觉-滤波去噪(邻域平均法滤波)

    # -*- coding: utf-8 -*- #code:myhaspl@myhaspl.com #邻域平均法滤波,半径为2 import cv2 import numpy as np fn=&qu ...

  5. 自动分组+合并完整的sql脚本

    BEGIN#前提:指定字符串长度为8字符定长#逻辑:循环8次,比对2个字符串相同索引位置下的数值大小,并取结果最大值.#示例:merge1(输入参数source1,输入参数source2,输出结果re ...

  6. A.归并排序

    归并排序 (求逆序数) 归并排序:递归+合并+排序 时间复杂度:O(n logn)    空间复杂度:O(n) 用途:1.排序  2.求逆序对数 Description In this problem ...

  7. C++对C语言的非面向对象特性扩充(3)

    今天要讲的是C++作用域运算符"::",强制类型转换的扩充,C++中相对于C中malloc和free函数的运算符new和delete,以及C++对C的一个重要扩充:引用(refer ...

  8. c++实现二分查找

    简要描述: 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除 困难. 条件:查找的数组必须要为有序数组. 二分查找的过程剩简要描述如下图: 二种实 ...

  9. win7 64下安装mysql-python报错的解决办法

    最近要使用django进行项目开发,需要使用mysql-python模块. 在本地搭建环境安装的时候却出现报错,Unable to find vcvarsall.bat  在网上找了很多资料,发现是w ...

  10. Spring注解配置

    配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...