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個(gè)方向走
{
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;
}
這道 在建立坐標(biāo)系上 出了一些問(wèn)題 因?yàn)樵诰仃囍?第一的下標(biāo)表示行 那我們就習(xí)慣用X 表示行 我的程序設(shè)計(jì)的時(shí)候 用y 表示行 在思路轉(zhuǎn)換的過(guò)程中出了點(diǎn)小問(wèn)題
posted on 2010-08-11 17:16
付翔 閱讀(214)
評(píng)論(0) 編輯 收藏 引用 所屬分類(lèi):
ACM 數(shù)據(jù)結(jié)構(gòu)