题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024
题意:求构成最长的直角或直线的圆点的个数。
思路:每个“.”暴力一遍找最长的直角或直线。
AC代码:
#include <stdio.h>
#include <string.h>
char ma[105][105];
int n;
int dfs1(int x,int y){
int i,a,b,ans=1;
a=x+1;
b=y;
while(ma[a][b]!='#'){
a++;
ans++;
}
a=x;
b=y+1;
while(ma[a][b]!='#'){
ans++;
b++;
}
return ans;
}
int dfs2(int x,int y){
int i,a,b,ans=1;
a=x+1;
b=y;
while(ma[a][b]!='#'){
a++;
ans++;
}
a=x;
b=y-1;
while(ma[a][b]!='#'){
ans++;
b--;
}
return ans;
}
int dfs3(int x,int y){
int i,a,b,ans=1;
a=x-1;
b=y;
while(ma[a][b]!='#'){
a--;
ans++;
}
a=x;
b=y+1;
while(ma[a][b]!='#'){
ans++;
b++;
}
return ans;
}
int dfs4(int x,int y){
int i,a,b,ans=1;
a=x-1;
b=y;
while(ma[a][b]!='#'){
a--;
ans++;
}
a=x;
b=y-1;
while(ma[a][b]!='#'){
ans++;
b--;
}
return ans;
}
int dfs5(int x,int y){
int i,a,b,ans=1;
a=x-1;
b=y-1;
while(ma[a][b]!='#'){
a--;
b--;
ans++;
}
a=x+1;
b=y-1;
while(ma[a][b]!='#'){
a++;
b--;
ans++;
}
return ans;
}
int dfs6(int x,int y){
int i,a,b,ans=1;
a=x-1;
b=y-1;
while(ma[a][b]!='#'){
a--;
b--;
ans++;
}
a=x-1;
b=y+1;
while(ma[a][b]!='#'){
a--;
b++;
ans++;
}
return ans;
}
int dfs7(int x,int y){
int i,a,b,ans=1;
a=x-1;
b=y+1;
while(ma[a][b]!='#'){
a--;
b++;
ans++;
}
a=x+1;
b=y+1;
while(ma[a][b]!='#'){
a++;
b++;
ans++;
}
return ans;
}
int dfs8(int x,int y){
int i,a,b,ans=1;
a=x+1;
b=y-1;
while(ma[a][b]!='#'){
a++;
b--;
ans++;
}
a=x+1;
b=y+1;
while(ma[a][b]!='#'){
a++;
b++;
ans++;
}
return ans;
}
int dfs(int x,int y){
int ans=0,k;
k=dfs1(x,y);
if(k>ans)
ans=k;
k=dfs2(x,y);
if(k>ans)
ans=k;
k=dfs3(x,y);
if(k>ans)
ans=k;
k=dfs4(x,y);
if(k>ans)
ans=k;
k=dfs5(x,y);
if(k>ans)
ans=k;
k=dfs6(x,y);
if(k>ans)
ans=k;
k=dfs7(x,y);
if(k>ans)
ans=k;
k=dfs8(x,y);
if(k>ans)
ans=k;
return ans;
}
int main(){
int i,j,m,ans;
while(~scanf("%d",&n),n){
memset(ma,'#',sizeof(ma));
getchar();
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
{
scanf("%c",&ma[i][j]);
}
getchar();
}
m=0;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(ma[i][j]=='.'){
ans=dfs(i,j);
if(ans>m)
m=ans;
}
}
}
printf("%d\n",m);
}
return 0;
}