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 200530740317 at 2007-09-17 11:27:21 on Problem 3226
#include<stdio.h>
#include<string.h>

#define MAXL 25


void outl(long t[])//输出
{
	char _out[100];
	int i,j,tmp,len=0;
	for(i=0;i<MAXL;i++)
	{
		tmp=t[i];
		for(j=0;j<4;j++)
		{
			_out[len++] = tmp%10+'0';
			tmp = tmp/10;
		}
	}
	len--;
	while(_out[len] == '0')len--;
	for(i=len;i>=0;i--)
	{
		putchar(_out[i]);
	}
	if(len<0)
		putchar('0');
	putchar('\n');
}

void mult(long m0[],long m1[],long m2)//乘法
{
	int i;
	long ans[2*MAXL];
	memset(ans,0,sizeof(ans));
	for(i=0;i<MAXL;i++)
	{
		ans[i]+=m1[i]*m2;
		if(ans[i]>=10000)
		{
			ans[i+1] += ans[i]/10000;
			ans[i] = ans[i]%10000;
		}
	}
	for(i=0;i<MAXL;i++)
		m0[i]=ans[i];
}
void addl(long a1[],long a2[])//加法
{
	int i;
	for(i=0;i<MAXL;i++)
	{
		a1[i] += a2[i];
		if(a1[i]>=10000)
		{
			a1[i+1] += a1[i]/10000;
			a1[i] = a1[i]%10000;
		}

	}
}


int main()
{
	long ans[MAXL],a[MAXL],b[26][MAXL],
		cont[30];//
	int n,i,j;
	while(scanf("%d",&n)==1&&n!=0)
	{
		char ch[30];
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		getchar();
		gets(ch);
		b[0][0] = 1;
		for(i=1;i<n;i++)
		{
			b[i][0]=1;
			mult(b[i],b[i-1],26-n+i);
		}
		memset(ans,0,sizeof(ans));
		memset(cont,0,sizeof(cont));
		for(i=1;i<n;i++)
		{
			for(j=i-1;j>=0;j--)
				if(ch[i]>ch[j])
					cont[i]++;
		}
		for(i=0;i<n;i++)
		{
			mult(a,b[n-i-1],ch[i]-'A'-cont[i]);
			addl(ans,a);
		}
		outl(ans);
	}
	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