hdu 5024 最长的L型

时间:2023-03-09 06:45:14
hdu 5024 最长的L型

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

找到一个最长的L型,L可以是斜着的

简单的模拟

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
int n;
char s[115][115];
bool vis[115][115];
int dx[] = {1,-1,0,0,1,-1,1,-1},
dy[] = {0,0,1,-1,-1,-1,1,1};
bool in(int x,int y)
{
return 0 <= x && x < n && 0 <= y && y < n;
}
int find(int x,int y)
{ int ans = 0;
for(int i = 0;i < 8;++i)
for(int j = i+1;j < 8;++j)if(dx[i]*dx[j] + dy[i]*dy[j] == 0){
int xx = x + dx[i],yy = y + dy[i];
int x1 = x + dx[j],y1 = y + dy[j];
int res = 1;
while(in(xx,yy) && s[xx][yy] == '.'){
res++;
xx += dx[i];
yy += dy[i];
}
while(in(x1,y1) && s[x1][y1] == '.'){
res++;
x1 += dx[j];
y1 += dy[j];
}
ans = max(res,ans);
}
return ans;
}
int main(){
while(~RD(n) && n){
//clr0(vis);
for(int i = 0;i < n;++i){
scanf("%s",s[i]);
}
int mx = 0;
for(int i = 0;i < n;++i)
for(int j = 0;j < n;++j){
if(s[i][j] == '.'){
mx = max(mx,find(i,j));
}
}
printf("%d\n",mx);
}
return 0;
}