付翔的专栏
在鄙视中成长 记录成长的点滴
posts - 106,  comments - 32,  trackbacks - 0

http://acm.hdu.edu.cn/showproblem.php?pid=3368

# include
<stdio.h>
# include
<math.h>
# include
<stdlib.h>
# include
<string.h>
# include
<ctype.h>
# include
<limits.h>
# include
<iostream>
# include
<algorithm>
using namespace std;

char map[9][9];
int dir[8][2= {
    {
0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}
};

bool isok(int x,int y)
{
    
if(x >= 0 && x < 8 && y >= 0 && y < 8)
        
return true;
    
return false;

}
int search(int y,int x)
{
    
int i = 0,curx = x,cury = y,result = 0,max = 0;
    
for(i = 0 ; i < 8 ; i ++)//往8个方向走
    {
         curx 
= x,cury = y;
        
while(isok(curx + dir[i][0],cury+dir[i][1]) && map[cury+dir[i][1]][curx + dir[i][0]] == 'L')
        {
            max 
++;
            curx 
+=dir[i][0];
            cury 
+=dir[i][1];
        }
        
if(isok(curx + dir[i][0],cury+dir[i][1]) && map[cury+dir[i][1]][curx + dir[i][0]] == 'D')
        {
             result 
+= max;
             max 
= 0;
        }
        
else max = 0;
    }
    
return result;
}
int main()
{    
    
//freopen("in.txt","r",stdin);
    
//freopen("out.txt","w",stdout);
    int T,caseId,i,j,k,t = INT_MIN,max = INT_MIN;
    cin
>>T;
    
for(caseId = 1; caseId <= T;caseId ++)
    {
        
for(i = 0; i < 8; i ++)
            
for(j = 0 ; j < 8; j ++)
                cin
>>map[i][j];
        
        
for(t = 0,max = 0,i = 0; i < 8; i ++)
        {
            
for(j = 0 ; j < 8; j ++)
            {
                
if(map[i][j] == '*')
                    t 
= search(i,j);
                
if(t > max)
                    max 
= t;
            }

        }
        printf(
"Case %d: %d\n",caseId,max);
    }
    
    
return 0;
}


这道 在建立坐标系上 出了一些问题  因为在矩阵中 第一的下标表示行 那我们就习惯用X 表示行 我的程序设计的时候 用y 表示行 在思路转换的过程中出了点小问题
posted on 2010-08-11 17:16 付翔 阅读(197) 评论(0)  编辑 收藏 引用 所属分类: ACM 数据结构

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2011年6月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

CSDN - 我的blog地址

博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜