Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么wa啊.. 不懂 谁帮忙看看 或者给个数据。

Posted by lijinwudemajia at 2010-04-11 15:42:49 on Problem 1471
#include <iostream>
using namespace std;

char map[210][210];
int dp[210][210];

int main()
{
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	int n;
	int count=0;
	while(scanf("%d ",&n)!=EOF&&n)
	{
		printf("Triangle #%d\n",++count);
		for(int i=0;i<n;++i)
		{
			gets(map[i]);
		}
		for(int i=0;i<2*n-1;++i)
		{
			if(map[0][i]=='#')
				dp[0][i]=0;
			else if(map[0][i]=='-')
				dp[0][i]=1;
		}
		int sum=0;
		for(int i=1;i<n;++i)
		{
			for(int j=i;j<n+(n-i-1);++j)
			{
				if(i%2==j%2)
				{
					if(map[i][j]=='-')
					{
						if(map[i-1][j]=='-')
							dp[i][j]=min(dp[i-1][j-1],dp[i-1][j+1])+1;
						else
							dp[i][j]=1;
					}
					else
						dp[i][j]=0;
					if(dp[i][j]>sum)
						sum=dp[i][j];
				}
			}
		}
		memset(dp,0,sizeof(dp));
		if(map[n-2][n-1]=='#')
			dp[n-2][n-1]=0;
		else
			dp[n-2][n-1]=1;
		for(int i=n-3;i>=0;--i)
		{
			for(int j=i;j<n+(n-i-1);++j)
			{
				if(i%2!=j%2)
				{
					if(map[i][j]=='#')
						dp[i][j]=0;
					else
					{
						if(map[i+1][j]=='-')
							dp[i][j]=min(dp[i+1][j-1],dp[i+1][j+1])+1;
						else
							dp[i][j]=1;
					}
					if(dp[i][j]>sum)
						sum=dp[i][j];
				}
			}
		}
		printf("The largest triangle area is %d.\n\n",sum*sum);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator