标签:
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1364 Accepted Submission(s): 540
1 #include<math.h> 2 #include<stdio.h> 3 #include<string.h> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 #define N 12 8 9 int dx[]={1,-1, 0, 0,1, 1,-1,-1}; 10 int dy[]={0, 0, 1,-1,1,-1,-1, 1}; 11 12 13 int n; 14 char mat[N][N]; 15 int v[N][N]; 16 int dfs1(int x,int y,int t) 17 { 18 if(mat[x][y]==‘D‘)return t; 19 if(mat[x][y]==‘*‘)return 0; 20 // printf("dfs(%d,%d,%d)\n",x,y,t+1); 21 dfs1(x+1,y,t+1); 22 } 23 int dfs2(int x,int y,int t) 24 { 25 if(mat[x][y]==‘D‘)return t; 26 if(mat[x][y]==‘*‘)return 0; 27 // printf("dfs2(%d,%d,%d)\n",x,y,t+1); 28 dfs2(x-1,y,t+1); 29 } 30 int dfs3(int x,int y,int t) 31 { 32 if(mat[x][y]==‘D‘)return t; 33 if(mat[x][y]==‘*‘)return 0; 34 // printf("dfs3(%d,%d,%d)\n",x,y,t+1); 35 dfs3(x,y+1,t+1); 36 } 37 int dfs4(int x,int y,int t) 38 { 39 if(mat[x][y]==‘D‘)return t; 40 if(mat[x][y]==‘*‘)return 0; 41 // printf("dfs4(%d,%d,%d)\n",x,y,t+1); 42 dfs4(x,y-1,t+1); 43 } 44 int dfs5(int x,int y,int t) 45 { 46 if(mat[x][y]==‘D‘)return t; 47 if(mat[x][y]==‘*‘)return 0; 48 // printf("dfs4(%d,%d,%d)\n",x,y,t+1); 49 dfs5(x+1,y+1,t+1); 50 } 51 int dfs6(int x,int y,int t) 52 { 53 if(mat[x][y]==‘D‘)return t; 54 if(mat[x][y]==‘*‘)return 0; 55 // printf("dfs4(%d,%d,%d)\n",x,y,t+1); 56 dfs6(x-1,y-1,t+1); 57 } 58 int dfs7(int x,int y,int t) 59 { 60 if(mat[x][y]==‘D‘)return t; 61 if(mat[x][y]==‘*‘)return 0; 62 // printf("dfs4(%d,%d,%d)\n",x,y,t+1); 63 dfs7(x-1,y+1,t+1); 64 } 65 int dfs8(int x,int y,int t) 66 { 67 if(mat[x][y]==‘D‘)return t; 68 if(mat[x][y]==‘*‘)return 0; 69 // printf("dfs4(%d,%d,%d)\n",x,y,t+1); 70 dfs8(x+1,y-1,t+1); 71 } 72 int dfs(int x,int y,int t) 73 { 74 int mm=0; 75 76 mm+=dfs1(x+1,y,t); 77 mm+=dfs2(x-1,y,t); 78 mm+=dfs3(x,y+1,t); 79 mm+=dfs4(x,y-1,t); 80 81 mm+=dfs5(x+1,y+1,t); 82 mm+=dfs6(x-1,y-1,t); 83 mm+=dfs7(x-1,y+1,t); 84 mm+=dfs8(x+1,y-1,t); 85 86 return mm; 87 } 88 89 90 int main() 91 { 92 int t;cin>>t;getchar(); 93 int tt=1; 94 for(int i=0;i<=9;i++) 95 { 96 mat[0][i]=‘*‘; 97 mat[9][i]=‘*‘; 98 } 99 for(int i=0;i<=9;i++) 100 { 101 mat[i][0]=‘*‘; 102 mat[i][9]=‘*‘; 103 } 104 105 while(t--) 106 { 107 memset(v,0,sizeof(v)); 108 int ma=0; 109 for(int i=1;i<=8;i++) 110 for(int j=1;j<=8;j++) 111 { 112 scanf(" %c",&mat[i][j]); 113 } 114 115 for(int i=1;i<=8;i++) 116 { 117 for(int j=1;j<=8;j++) 118 { 119 if(mat[i][j]==‘*‘) 120 { 121 // printf("%d,%d\n",i,j); 122 ma=max(ma, dfs(i,j,0) ); 123 // printf("%d,%d ma = %d\n",i,j,ma); 124 } 125 } 126 } 127 printf("Case %d: ",tt++); 128 cout<<ma<<endl; 129 } 130 return 0; 131 } 132 133 /* 134 33 135 ******** 136 ******** 137 ******** 138 ***LD*** 139 ***DL*** 140 ******** 141 ******** 142 ******** 143 144 ******** 145 ******** 146 **DLL*** 147 **DLLL** 148 **DLD*** 149 ******** 150 ******** 151 ******** 152 153 ******** 154 ******** 155 *D****** 156 *DLLD*** 157 ***LL*** 158 **D*D*** 159 ******** 160 ******** 161 162 ******** 163 ******** 164 *D****** 165 *DLLD*** 166 ***LL*** 167 **D*L*** 168 *****L** 169 ******** 170 171 ******D* 172 *****L** 173 *D**L*** 174 *DLLLLL* 175 **LLL*** 176 *LD*L*** 177 *****L** 178 ******** 179 180 181 182 */
标签:
原文地址:http://www.cnblogs.com/wmxl/p/4693207.html