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
原创粉丝点击