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 deep_you at 2005-10-26 19:29:57 on Problem 1189
#include <stdio.h>
#include <memory.h>
char map[50][50];
long value[60][60];
long zg(long num1,long num2)
{
	while(num1%num2!=0)
	{
		long k;
		k=num1%num2;
		num1=num2;
		num2=k;
	}
	return num2;
}

int main()
{
	int n,m,i,j;
	long sum,nn;
	char str[1000];
	scanf("%d %d",&n,&m);
	getchar();
	for(i=0;i<n;i++)
	{
		int p=0;
		j=0;
		gets(str);
		while(str[p])
		{
			if(str[p]=='*'||str[p]=='.')
			{
				map[i][j]=str[p];
				j++;
			}
			p++;
		}

	}
	memset(value,0,sizeof(int)*60*60);
	value[0][0]=1;
	for(i=0;i<n;i++)
	{
		for(j=0;j<=i;j++)
		{
			if(value[i][j]==0)continue;
			if(i!=n&&map[i][j]=='.')value[i+2][j+1]+=value[i][j]*4;
			else
			{
				value[i+1][j]+=value[i][j];
				value[i+1][j+1]+=value[i][j];
			}
		}
	}
	sum=0;
	for(j=0;j<=n;j++)
	{
		sum+=value[n][j];
	}
	if(value[n][m]!=0)
	{
		nn=zg(sum,value[n][m]);
		printf("%ld/%ld\n",value[n][m]/nn,sum/nn);
	}
	else printf("0/1\n");
	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