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

Re:康拓展开+高精度

Posted by infoG at 2014-08-09 10:55:04 on Problem 1349
In Reply To:康拓展开+高精度 Posted by:infoG at 2013-11-10 16:58:43
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct bignumber
{
	int dig;
	int d[100];
} c1={1,0,1};
bignumber jc[55],ans;
int f[55];
int i,j,k,n,l,m,ii=0;
char s[200];

bignumber cheng(bignumber a,int b)
{
	bignumber c=a;
	int i;

	for (i=1;i<=c.dig;i++)
		c.d[i]=c.d[i]*b;
	
	for (i=1;i<=c.dig;i++)
	{
		if (c.d[i]>=10)
		{
			c.d[i+1]+=c.d[i]/10;
			c.d[i]=c.d[i]%10;
		}
	}
	while (c.d[c.dig+1]>0)
	{
		c.dig++;
		if (c.d[c.dig]>=10)
		{
			c.d[c.dig+1]+=c.d[c.dig]/10;
			c.d[c.dig]=c.d[c.dig]%10;
		}
	}
	return c;
}
bignumber jia(bignumber a,bignumber b)
{
	bignumber c=a;
	int i,l;

	if (a.dig>b.dig) l=a.dig;
		else l=b.dig;

	for (i=1;i<=l;i++)
		c.d[i]=a.d[i]+b.d[i];
	
	for (i=1;i<=c.dig;i++)
	{
		if (c.d[i]>=10)
		{
			c.d[i+1]+=c.d[i]/10;
			c.d[i]=c.d[i]%10;
		}
	}
	while (c.d[c.dig+1]>0)
	{
		c.dig++;
		if (c.d[c.dig]>=10)
		{
			c.d[c.dig+1]+=c.d[c.dig]/10;
			c.d[c.dig]=c.d[c.dig]%10;
		}
	}
	return c;
}
bignumber zhankai(int n)
{
	int i,j,temp;
	bignumber t;

	t.dig=1;
	memset(t.d,0,sizeof(t.d));

	for (i=0;i<n;i++)
	{
		temp=0;
		for (j=i+1;j<n;j++)
			if (f[j]<f[i]) temp++;
		t=jia(t,cheng(jc[n-i-1],temp));
	}
	return t;
}
int main()
{
	jc[1].dig=1;jc[1].d[1]=1;
	for (i=2;i<=55;i++)
		jc[i]=cheng(jc[i-1],i);

	ii=0;
	while (scanf("%s",s),s[0]!='-')
	{
		ii++;
		l=strlen(s);
		k=0;
		for (i=0;i<=3;i++)
			if (s[i]>='0'&&s[i]<='9') k=k*10+s[i]-48;
		n=k;
		
		j=3;k=0;

		do
		{
			j++;
		}
		while (s[j]<'0'||s[j]>'9');

		m=0;
		for (i=j;i<l;i++)
		{
			if (s[i]>='0'&&s[i]<='9') k=k*10+s[i]-48;
				else
				{
					f[m]=k;
					k=0;
					m++;
				}
		}

		if (ii!=1) printf(",");
		ans=jia(zhankai(n),c1);
		for (i=ans.dig;i>=1;i--)
			printf("%d",ans.d[i]);
		
	}
	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