模拟吧,算是。。。
被这个题wa到哭,真是什么都不想说了。。。上代码
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 5 struct node { 6 int x,y; 7 char c; 8 }q[10]; 9 10 int main (){ 11 int n,x,y; 12 int kase=0; 13 int map[30][30]; 14 while (cin>>n>>x>>y){ 15 if (n+x+y==0) 16 break ; 17 memset (map,0,sizeof map); 18 for (int i=0;i<n;i++){ 19 cin>>q[i].c>>q[i].x>>q[i].y; 20 map[q[i].x][q[i].y]=2; 21 } 22 int flag=1; 23 for (int i=0;i<n;i++){ 24 if (q[i].c==‘G‘){ 25 for (int j=q[i].x-1;j>0;j--){ 26 if (map[j][q[i].y]==2||map[j][q[i].y]==3){ 27 map[j][q[i].y]=3; 28 break ; 29 } 30 if (j==x&&q[i].y==y){ 31 flag=0; 32 break ; 33 } 34 map[j][q[i].y]=1; 35 } 36 } 37 else if (q[i].c==‘R‘){ 38 for (int j=q[i].x-1;j>0;j--){ 39 if (map[j][q[i].y]==2||map[j][q[i].y]==3){ 40 map[j][q[i].y]=3; 41 break ; 42 } 43 map[j][q[i].y]=1; 44 } 45 for (int j=q[i].x+1;j<20;j++){ 46 if (map[j][q[i].y]==2||map[j][q[i].y]==3){ 47 map[j][q[i].y]=3; 48 break ; 49 } 50 map[j][q[i].y]=1; 51 } 52 for (int j=q[i].y-1;j>0;j--){ 53 if (map[q[i].x][j]==2||map[q[i].x][j]==3){ 54 map[q[i].x][j]=3; 55 break ; 56 } 57 map[q[i].x][j]=1; 58 } 59 for (int j=q[i].y+1;j<20;j++){ 60 if (map[q[i].x][j]==2||map[q[i].x][j]==3){ 61 map[q[i].x][j]=3; 62 break ; 63 } 64 map[q[i].x][j]=1; 65 } 66 } 67 else if (q[i].c==‘H‘){ 68 if (map[q[i].x+1][q[i].y]!=2&&map[q[i].x+1][q[i].y]!=3){ 69 map[q[i].x+2][q[i].y+1]=map[q[i].x+2][q[i].y+1]==2||map[q[i].x+2][q[i].y+1]==3?3:1; 70 map[q[i].x+2][q[i].y-1]=map[q[i].x+2][q[i].y-1]==2||map[q[i].x+2][q[i].y-1]==3?3:1; 71 } 72 if (q[i].x>1&&map[q[i].x-1][q[i].y]!=2&&map[q[i].x-1][q[i].y]!=3){ 73 map[q[i].x-2][q[i].y+1]=map[q[i].x-2][q[i].y+1]==2||map[q[i].x-2][q[i].y+1]==3?3:1; 74 map[q[i].x-2][q[i].y-1]=map[q[i].x-2][q[i].y-1]==2||map[q[i].x-2][q[i].y-1]==3?3:1; 75 } 76 if (map[q[i].x][q[i].y+1]!=2&&map[q[i].x][q[i].y+1]!=3){ 77 map[q[i].x+1][q[i].y+2]=map[q[i].x+1][q[i].y+2]==2||map[q[i].x+1][q[i].y+2]==3?3:1; 78 map[q[i].x-1][q[i].y+2]=map[q[i].x-1][q[i].y+2]==2||map[q[i].x-1][q[i].y+2]==3?3:1; 79 } 80 if (q[i].y>1&&map[q[i].x][q[i].y-1]!=2&&map[q[i].x][q[i].y-1]!=3){ 81 map[q[i].x+1][q[i].y-2]=map[q[i].x+1][q[i].y-2]==2||map[q[i].x+1][q[i].y-2]==3?3:1; 82 map[q[i].x-1][q[i].y-2]=map[q[i].x-1][q[i].y-2]==2||map[q[i].x-1][q[i].y-2]==3?3:1; 83 } 84 } 85 else { 86 int temp=0; 87 for (int j=q[i].x+1;j<20;j++){ 88 if (temp==1&&map[j][q[i].y]==0) 89 map[j][q[i].y]=1; 90 if (map[j][q[i].y]==2||map[j][q[i].y]==3) 91 temp++; 92 if (temp==2){ 93 map[j][q[i].y]=3; 94 break ; 95 } 96 } 97 temp=0; 98 for (int j=q[i].x-1;j>0;j--){ 99 if (temp==1&&map[j][q[i].y]==0) 100 map[j][q[i].y]=1; 101 if (map[j][q[i].y]==2||map[j][q[i].y]==3) 102 temp++; 103 if (temp==2){ 104 map[j][q[i].y]=3; 105 break ; 106 } 107 } 108 temp=0; 109 for (int j=q[i].y-1;j>0;j--){ 110 if (temp==1&&map[q[i].x][j]==0) 111 map[q[i].x][j]=1; 112 if (map[q[i].x][j]==2||map[q[i].x][j]==3) 113 temp++; 114 if (temp==2){ 115 map[q[i].x][j]=3; 116 break ; 117 } 118 } 119 temp=0; 120 for (int j=q[i].y+1;j<20;j++){ 121 if (temp==1&&map[q[i].x][j]==0) 122 map[q[i].x][j]=1; 123 if (map[q[i].x][j]==2||map[q[i].x][j]==3) 124 temp++; 125 if (temp==2){ 126 map[q[i].x][j]=3; 127 break ; 128 } 129 } 130 } 131 } 132 if (map[x][y]==0||map[x][y]==2) 133 flag=0; 134 if (x<3) 135 if (map[x+1][y]==0||map[x+1][y]==2) 136 flag=0; 137 if (y<6) 138 if (map[x][y+1]==0||map[x][y+1]==2) 139 flag=0; 140 if (x>1) 141 if (map[x-1][y]==0||map[x-1][y]==2) 142 flag=0; 143 if (y>4) 144 if (map[x][y-1]==0||map[x][y-1]==2) 145 flag=0; 146 147 //for (int i=1;i<=10;i++){ 148 // for (int j=1;j<=10;j++) 149 // cout<<map[i][j]; 150 // cout<<endl; 151 //} 152 153 //if (kase++) 154 // cout<<endl; 155 if (flag) 156 cout<<"YES"<<endl; 157 else cout<<"NO"<<endl; 158 } 159 return 0; 160 }
HDU 4121 Xiangqi,布布扣,bubuko.com
原文:http://www.cnblogs.com/gfc-g/p/3851731.html