http://acm.hdu.edu.cn/showproblem.php?pid=3368
模拟
我的代码
1 #include <stdio.h>
2 const int dx[8]={0,1,1,1,0,-1,-1,-1};
3 const int dy[8]={1,1,0,-1,-1,-1,0,1};
4 char maze[10][10];
5 int f(int xx,int yy)
6 {
7 int d,cnt=0;
8 for (d=0;d<8;d++)
9 {
10 int c=0,x=xx,y=yy;
11 do{
12 x+=dx[d]; y+=dy[d];
13 c++;
14 }while (maze[x][y]=='L');
15 if (maze[x][y]=='D') cnt+=c-1;
16 }
17 return cnt;
18 }
19 int main()
20 {
21 int T,C=0;
22 scanf("%d",&T);
23 int i,j,ans;
24 while (T--)
25 {
26 ans=0;
27 for (i=1;i<=8;i++) scanf("%s",maze[i]+1);
28 for (i=1;i<=8;i++)
29 for (j=1;j<=8;j++) if (maze[i][j]=='*')
30 {
31 int t=f(i,j);
32 if (t>ans) ans=t;
33 }
34 printf("Case %d: ",++C);
35 printf("%d\n",ans);
36 }
37 return 0;
38 }