hdu4121 Xiangqi
来源:互联网 发布:最坏的一天 电影 知乎 编辑:程序博客网 时间:2024/05/21 03:28
import java.lang.*; import java.util.*; import java.math.*; class Node{ public int x , y ; Node(){} Node(int x , int y){ this.x = x ; this.y = y ; }}class Board{ public static final int maxn = 12 ; public static Vector<Node> G = new Vector<Node>() ; public static Vector<Node> R = new Vector<Node>() ; public static Vector<Node> H = new Vector<Node>() ; public static Vector<Node> C = new Vector<Node>() ; public static int sx , sy ; public static boolean [][]is = new boolean[maxn][maxn] ; public static int d[][] = {{-1 ,0} , {0 , -1} , {1 , 0} , {0 , 1} } ; public static int da[][] = {{-2 , -1}, {-2 ,1} , {-1,2} , {1,2} , {2 ,1} , {2,-1} , {1,-2} , {-1,-2} } ; public static int db[][] = {{-1,0}, {-1,0} , {0,1} , {0,1} , {1,0} , {1,0} , {0,-1} , {0,-1} } ; public Board(){} public static boolean can(int x , int y){ return 1 <= x && x <= 3 && 4 <= y && y <= 6 ; } public static boolean can2(int x , int y){ return 1 <= x && x <= 10 && 1 <= y && y <= 9 ; } public static int no(){ int ex = G.get(0).x ; int ey = G.get(0).y ; if(ey == sy){ for(int x = Math.min(sx , ex) + 1 ; x < Math.max(sx , ex) ; x++){ if(is[x][ey]) return 0 ; } return 1 ; } return 0 ; } public static int ok(int nx , int ny){ int ex , ey ; ex = G.get(0).x ; ey = G.get(0).y ; if(ey == ny){ int f = 0 ; for(int x = Math.min(nx , ex) + 1 ; x < Math.max(nx , ex) ; x++){ if(is[x][ey]) f = 1 ; } if(f == 0) return 0 ; } for(int i = 0 ; i < H.size() ; i++){ ex = H.get(i).x ; ey = H.get(i).y ; for(int k = 0 ; k < 8 ; k++){ int bx = ex + db[k][0] ; int by = ey + db[k][1] ; int ax = ex + da[k][0] ; int ay = ey + da[k][1] ; if(! can2(bx , by)) continue ; if(! can2(ax , ay)) continue ; if(!is[bx][by] && ax == nx && ay == ny) return 0 ; } } for(int i = 0 ; i < R.size() ; i++){ ex = R.get(i).x ; ey = R.get(i).y ; if(ex == nx && ey == ny) continue ; if(ex == nx){ int f = 0 ; for(int y = Math.min(ny , ey) + 1 ; y < Math.max(ny , ey) ; y++){ if(is[ex][y]) f = 1 ; } if(f == 0) return 0 ; } if(ey == ny){ int f = 0 ; for(int x = Math.min(nx , ex) + 1 ; x < Math.max(nx , ex) ; x++){ if(is[x][ey]) f = 1 ; } if(f == 0) return 0 ; } } for(int i = 0 ; i < C.size() ; i++){ ex = C.get(i).x ; ey = C.get(i).y ; if(ex == nx){ int f = 0 ; for(int y = Math.min(ny , ey) + 1 ; y < Math.max(ny , ey) ; y++){ if(is[ex][y]) f++ ; } if(f == 1) return 0 ; } if(ey == ny){ int f = 0 ; for(int x = Math.min(nx , ex) + 1 ; x < Math.max(nx , ex) ; x++){ if(is[x][ey]) f++ ; } if(f == 1) return 0 ; } } return 1 ; } public static String gao(){ if(no() == 1) return "NO" ; for(int i = 0 ; i < 4 ; i++){ int x = sx + d[i][0] ; int y = sy + d[i][1] ; if(! can(x , y)) continue ; if(ok(x , y) == 1) return "NO" ; } return "YES" ; } public static void Clear(){ G.clear() ; R.clear() ; H.clear() ; C.clear() ; for(int i = 0 ; i < maxn ; i++){ for(int j = 0 ; j < maxn ; j++) is[i][j] = false ; } } public static void SetXY(int x , int y){ sx = x ; sy = y ; } public static void Setborad(String s , int x , int y){ if(s.compareTo("G") == 0) G.add(new Node(x , y)) ; else if(s.compareTo("R") == 0) R.add(new Node(x , y)) ; else if(s.compareTo("H") == 0) H.add(new Node(x , y)) ; else if(s.compareTo("C") == 0) C.add(new Node(x , y)) ; is[x][y] = true ; }}public class Main{ public static void main(String srgs[]){ int n , sx , sy ; Board bod = new Board() ; Scanner cin = new Scanner(System.in) ; while(cin.hasNext()){ n = cin.nextInt() ; sx = cin.nextInt() ; sy = cin.nextInt() ; if(n == 0 && sx == 0 && sy == 0) break ; bod.Clear(); bod.SetXY(sx , sy) ; for(int i = 1 ; i <= n ; i++){ bod.Setborad(cin.next(), cin.nextInt(), cin.nextInt() ); } System.out.println(bod.gao()) ; } }}
0 0
- hdu4121 xiangqi
- hdu4121 xiangqi
- hdu4121 Xiangqi
- hdu4121 Xiangqi && uva1589 Xiangqi (模拟)
- 【HDU4121】Xiangqi模拟象棋checkmate
- UVa 1589Xiangqi(模拟 HDU4121)
- HDU4121 UVa1589 Xiangqi 解题报告
- POJ4001/HDU4121 Xiangqi 大模拟
- hdu4121/poj 4001 Xiangqi(模拟)
- BFS、模拟:UVa1589/POJ4001/hdu4121-Xiangqi
- 2011 Asia Fuzhou Regional Contest-1001 hdu4121 Xiangqi
- Xiangqi
- hdu4121 神模拟
- UVA1589(HDU4121)
- POJ4001 Xiangqi
- Uva1589 - Xiangqi
- 1589 - Xiangqi
- poj4001 Xiangqi
- shell操作数据库脚本
- 数据库系统概论课后习题答案第二章
- JAVA笔记:Java IO流总结
- [Java]读取文件内容方法总结
- c99在不同编译器的实现情况
- hdu4121 Xiangqi
- HTML5/CSS3hack
- 译Variance Shadow Maps
- [C++]LeetCode: 83 Combinations (回溯法)
- i os 开发者证书 申请 详解
- ORACLE PL/SQL编程之五:异常错误处理
- UiNavigationController的使用
- 数据库系统概论课后习题答案第三章
- IntentService