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

高精乘法步进值10就能AC,但是10000就WA了,谁能解释下为什么?

Posted by elcwoo at 2010-07-21 11:14:28 on Problem 1906
#include<stdio.h>
#include<stdlib.h>

int* mult(const int* a,const int* b)
{
	int alen,blen,clen,lop1,lop2,rec;
	int* ret;
	rec=1;
	alen=a[0];
	blen=b[0];
	clen=alen+blen;
	ret = malloc(sizeof(int)*(alen+blen+1));
	for(lop1=1;lop1<=clen;lop1++)
		ret[lop1]=0;
	for(lop1=1;lop1<=alen;lop1++)
		for(lop2=1;lop2<=blen;lop2++)
			ret[lop1+lop2-1]+=a[lop1]*b[lop2];
	for(lop1=2;lop1<=clen;lop1++)
	{
AC:		ret[lop1]+=ret[lop1-1]/10;
//WA: ret[lop1]+=ret[lop1-1]/10000;
AC:		ret[lop1-1]%=10;
//WA: ret[lop1-1]%=10000;
		if(ret[lop1])rec=lop1;
	}
	ret[0]=rec;
	return ret;
}

void main()
{
	int lop,lop1;
	int flag;
	int* n[64];
	long long int tar;
	int b[2]={1,3};
	n[0]=malloc(sizeof(int*)*2);
	n[0][0]=1;
	n[0][1]=1;
	for(lop=1;lop<64;lop++)
		n[lop] = mult( n[lop-1] , b );
	do
	{
		scanf("%lld",&tar);
		if(!tar)break;
		tar--;
		flag=1;
		printf("{");
		for(lop=0;lop<64;lop++)
		{
			if((tar>>lop)&1)
			{
				if(flag)flag=0;
				else
					printf(",");
				printf(" ");
				for(lop1=n[lop][0];lop1;lop1--)
				{
					printf("%d",n[lop][lop1]);
				}
			}
		}
		printf(" }\n");
	}while(1);
}

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