| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位能帮我看看为什么错,上三角和下三角考虑了,#include<iostream>
using namespace std;
char a[401][401];
int len,n,beg,end,s1,s2;
// 暴搜
int check1(int beg,int end,int key)//检查头朝上的
{
int i,j,k,ss=0;
while(beg<=end)
{
if(key<0)return 0;
for(j=beg;j<=end;j++)
{
if(a[key][j]=='#')return 0;
}
ss+=(end-beg+1);
beg++;
end--;
key--;
}
return ss;
}
int check2(int beg,int end,int key)//检查头朝下的
{
int i,j,k,ss=0;
while(beg<=end)
{
if(key>=n)return 0;
for(j=beg;j<=end;j++)
{
if(a[key][j]=='#')return 0;
}
ss+=(end-beg+1);
beg++;
end--;
key++;
}
return ss;
}
int main()
{
int i,j,k,c=1,sum;
while(scanf("%d ",&n)!=EOF)
{
if(n==0)break;
memset(a,' ',sizeof(a));
sum=0;
for(i=0;i<n;i++)
{
gets(a[i]);
if(i==0){len=strlen(a[i]);}
}
/* for(i=0;i<n;i++)
{
for(j=0;j<len;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
} */
for(i=0;i<n;i++)
{
for(j=0;j<len;j++)
{
if(a[i][j]=='-')
{
beg=j;
int count=1;
for(k=beg+1;k<len;k++)
{
if(a[i][k]=='-')count++;
else break;
}
end=j+count-1;
if(count%2)
{
if(i%2!=j%2)//向上
{
s1=check1(beg,end,i);
if(s1>sum)sum=s1;
}
else if(i%2==j%2)//向下
{
s2=check2(beg,end,i);
if(s2>sum)sum=s2;
}
}
}
}
}
printf("Triangle #%d\n",c++);
printf("The largest triangle area is %d.\n\n",sum);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator