/*
zoj_1245 搜索
直接暴力,再次犯了该用getline的时候用cin的错误。切忌!!
注意分角向上的三角形和向下的三角形两种。
*/
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string s[110];
int n;
bool check( int x1,int x2,int y )
{
int i;
for( i=x1;i<=x2;i++ )
{
if( s[y][i]=='#' )
break;
}
if( i==x2+1 ) return true;
else return false;
}
int find( int x1,int x2,int y,int choice )
{
int sum;
sum=0;
while( 1 )
{
if( x1<y || x2>=2*n-y-1 || y<0 )
break;
if( check( x1,x2,y ) )
{
//cout<<y<<" "<<x1<<" "<<x2<<endl;
sum+=x2-x1+1;
x1--;
x2++;
y+=choice;
}
else break;
}
return sum;
}
int main()
{
int t,i,j,maxi,count;
count=1;
while( cin>>n && n )
{
cin.get();
for( i=0;i<n;i++ )
{
getline(cin,s[i]);
}
maxi=-1;
for( i=0;i<n;i++ )
{
//cout<<i<<" "<<2*n-i-1<<endl;
for( j=i;j<2*n-i-1;j++ )
{
if( (i%2==0 && j%2==0) || (i%2==1) && (j%2==1) && s[i][j]=='-' )
if( ( t=find( j,j,i,-1 ) )>maxi )
maxi=t;
if( (i%2==0 && j%2==1) || (i%2==1) && (j%2==0) && s[i][j]=='-' )
if( ( t=find( j,j,i,1 ) )>maxi )
maxi=t;
}
}
cout<<"Triangle #"<<count<<endl;
cout<<"The largest triangle area is "<<maxi<<".\n\n";
count++;
}
}
zoj 1245
最新推荐文章于 2022-04-25 00:14:08 发布