HDU3368+枚举
题意看不懂的直接看百度百科对黑白棋的解释。。。
做法:分情况讨论,一共8个方向。
1 /* 2 搜索 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 const int maxn = 10; 7 char mat[ maxn ][ maxn ]; 8 const int dx[]={-1,1,-1,1}; 9 const int dy[]={1,-1,-1,1}; 10 11 int max( int a,int b ){ 12 return a>b?a:b; 13 } 14 15 bool in( int x,int y ){ 16 if( x>=1&&x<=8&&y>=1&&y<=8 ) return true; 17 else return false; 18 } 19 20 int solve( int x,int y ){ 21 int ans = 0; 22 int pos; 23 24 pos = -1; 25 for( int i=y+1;i<=8;i++ ){ 26 if( mat[x][i]=='D' ){ 27 pos = i; 28 break; 29 } 30 } 31 if( pos!=-1 ){ 32 for( int i=y+1;i<=pos;i++ ){ 33 if( mat[x][i]=='*' ){ 34 pos = -1; 35 break; 36 } 37 } 38 } 39 if( pos!=-1 ){ 40 for( int i=y+1;i<=pos;i++ ){ 41 if( mat[x][i]=='L' ) 42 ans++; 43 } 44 } 45 //right 46 pos = -1; 47 for( int i=y-1;i>=1;i-- ){ 48 if( mat[x][i]=='D' ){ 49 pos = i; 50 break; 51 } 52 } 53 if( pos!=-1 ){ 54 for( int i=y-1;i>=pos;i-- ){ 55 if( mat[x][i]=='*' ){ 56 pos = -1; 57 break; 58 } 59 } 60 } 61 if( pos!=-1 ){ 62 for( int i=y-1;i>=pos;i-- ){ 63 if( mat[x][i]=='L' ) 64 ans++; 65 } 66 } 67 //left 68 pos = -1; 69 for( int i=x+1;i<=8;i++ ){ 70 if( mat[i][y]=='D' ){ 71 pos = i; 72 break; 73 } 74 } 75 if( pos!=-1 ){ 76 for( int i=x+1;i<=pos;i++ ){ 77 if( mat[i][y]=='*' ){ 78 pos = -1; 79 break; 80 } 81 } 82 } 83 if( pos!=-1 ){ 84 for( int i=x+1;i<=pos;i++ ){ 85 if( mat[i][y]=='L' ) 86 ans++; 87 } 88 } 89 //down 90 pos = -1; 91 for( int i=x-1;i>=1;i-- ){ 92 if( mat[i][y]=='D' ){ 93 pos = i; 94 break; 95 } 96 } 97 if( pos!=-1 ){ 98 for( int i=x-1;i>=pos;i-- ){ 99 if( mat[i][y]=='*' ){ 100 pos = -1; 101 break; 102 } 103 } 104 } 105 if( pos!=-1 ){ 106 for( int i=x-1;i>=pos;i-- ){ 107 if( mat[i][y]=='L' ) 108 ans++; 109 } 110 } 111 //up 112 int posx,posy; 113 int K; 114 posx = -1; 115 for( int k=1;k<=8;k++ ){ 116 int tx = x+k*dx[0]; 117 int ty = y+k*dy[0]; 118 if( in(tx,ty)==false ) break; 119 if( mat[tx][ty]=='D' ){ 120 posx = tx; 121 posy = ty; 122 K = k; 123 break; 124 } 125 } 126 if( posx!=-1 ){ 127 for( int k=1;k<=K;k++ ){ 128 int tx = x+k*dx[0]; 129 int ty = y+k*dy[0]; 130 if( in(tx,ty)==false ) break; 131 if( mat[tx][ty]=='*' ){ 132 posx = -1; 133 break; 134 } 135 } 136 } 137 if( posx!=-1 ){ 138 for( int k=1;k<=K;k++ ){ 139 int tx = x+k*dx[0]; 140 int ty = y+k*dy[0]; 141 if( in(tx,ty)==false ) break; 142 if( mat[tx][ty]=='L' ) 143 ans++; 144 } 145 } 146 //right && up 147 posx = -1; 148 for( int k=1;k<=8;k++ ){ 149 int tx = x+k*dx[1]; 150 int ty = y+k*dy[1]; 151 if( in(tx,ty)==false ) break; 152 if( mat[tx][ty]=='D' ){ 153 posx = tx; 154 posy = ty; 155 K = k; 156 break; 157 } 158 } 159 if( posx!=-1 ){ 160 for( int k=1;k<=K;k++ ){ 161 int tx = x+k*dx[1]; 162 int ty = y+k*dy[1]; 163 if( in(tx,ty)==false ) break; 164 if( mat[tx][ty]=='*' ){ 165 posx = -1; 166 break; 167 } 168 } 169 } 170 if( posx!=-1 ){ 171 for( int k=1;k<=K;k++ ){ 172 int tx = x+k*dx[1]; 173 int ty = y+k*dy[1]; 174 if( in(tx,ty)==false ) break; 175 if( mat[tx][ty]=='L' ) 176 ans++; 177 } 178 } 179 //left && down 180 posx = -1; 181 for( int k=1;k<=8;k++ ){ 182 int tx = x+k*dx[2]; 183 int ty = y+k*dy[2]; 184 if( in(tx,ty)==false ) break; 185 if( mat[tx][ty]=='D' ){ 186 posx = tx; 187 posy = ty; 188 K = k; 189 break; 190 } 191 } 192 if( posx!=-1 ){ 193 for( int k=1;k<=K;k++ ){ 194 int tx = x+k*dx[2]; 195 int ty = y+k*dy[2]; 196 if( in(tx,ty)==false ) break; 197 if( mat[tx][ty]=='*' ){ 198 posx = -1; 199 break; 200 } 201 } 202 } 203 if( posx!=-1 ){ 204 for( int k=1;k<=K;k++ ){ 205 int tx = x+k*dx[2]; 206 int ty = y+k*dy[2]; 207 if( in(tx,ty)==false ) break; 208 if( mat[tx][ty]=='L' ) 209 ans++; 210 } 211 } 212 //left &&up 213 posx = -1; 214 for( int k=1;k<=8;k++ ){ 215 int tx = x+k*dx[3]; 216 int ty = y+k*dy[3]; 217 if( in(tx,ty)==false ) break; 218 if( mat[tx][ty]=='D' ){ 219 posx = tx; 220 posy = ty; 221 K = k; 222 break; 223 } 224 } 225 if( posx!=-1 ){ 226 for( int k=1;k<=K;k++ ){ 227 int tx = x+k*dx[3]; 228 int ty = y+k*dy[3]; 229 if( in(tx,ty)==false ) break; 230 if( mat[tx][ty]=='*' ){ 231 posx = -1; 232 break; 233 } 234 } 235 } 236 if( posx!=-1 ){ 237 for( int k=1;k<=K;k++ ){ 238 int tx = x+k*dx[3]; 239 int ty = y+k*dy[3]; 240 if( in(tx,ty)==false ) break; 241 if( mat[tx][ty]=='L' ) 242 ans++; 243 } 244 } 245 //right && down 246 247 return ans; 248 } 249 250 int main(){ 251 int T; 252 scanf("%d",&T); 253 int ca = 1; 254 while( T-- ){ 255 for( int i=1;i<=8;i++ ){ 256 scanf("%s",mat[i]+1); 257 } 258 //memset( vis,false,sizeof( vis ) ); 259 int ans = 0; 260 for( int i=1;i<=8;i++ ){ 261 for( int j=1;j<=8;j++ ){ 262 if( mat[i][j]=='*' ){ 263 ans = max( ans,solve( i,j ) ); 264 //if( ans>0 ) printf("attention:%d %d \n",i,j); 265 } 266 } 267 } 268 printf("Case %d: %d\n",ca++,ans); 269 } 270 return 0; 271 }
keep moving...