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

不容易啊!!! 2180K 32MS

Posted by ACAccepted at 2019-08-21 09:19:51 on Problem 1737 and last updated at 2019-08-21 09:24:54
#include <cstdio>
#include <cstring>
#include <algorithm>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;

template<typename T>
inline T read()
{
	T x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){if (c=='-')f=-1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-48;c=getchar();}
	return x*f;
}

const int MAXN=51;
const int SIZE=4;
const int BIT=10000;
const int MAXM=201;
int n;

struct prec
{
	int len;
	int x[MAXM];
	
	inline prec()
	{
		len=0;
		memset(x,0,sizeof(x));
	}
	
	inline struct prec operator = (int tmp)
	{
		while (tmp)
		{
			x[++len]=tmp%BIT;
			tmp/=BIT;
		}
		return *this;
	}
	
	inline void print(char c)
	{
		printf("%d",x[len]);
		for (int i=len-1;i>=1;i--) printf("%04d",x[i]);
		printf("%c",c);
	}
	
	inline struct prec operator + (int tmp)
	{
		struct prec ans;ans.len=len;
		for (int i=1;i<=len;i++)
		{
			ans.x[i]=x[i]+tmp;
			tmp=ans.x[i]/10;
			ans.x[i]%=10;
		}
		if (tmp>0)
			ans.x[++ans.len]=tmp;
		return ans;
	}
	
	inline struct prec operator + (struct prec tmp)
	{
		struct prec ans;ans.len=max(len,tmp.len);
		int c=0;
		for (int i=1;i<=ans.len;i++)
		{
			ans.x[i]=x[i]+tmp.x[i]+c;
			c=ans.x[i]/BIT;
			ans.x[i]%=BIT;
		}
		if (c>0) ans.x[++ans.len]=c;
		return ans;
	}
	
	inline struct prec operator - (struct prec tmp)
	{
		struct prec ans;ans.len=len;
		for (int i=1;i<=len;i++)
		{
			ans.x[i]+=(x[i]-tmp.x[i]);
			if (ans.x[i]<0) ans.x[i]+=BIT,ans.x[i+1]--;
		}
		while (ans.x[ans.len]==0) ans.len--;
		return ans;
	}

	inline struct prec operator * (int tmp)
	{
		struct prec ans;ans.len=len;
		int c=0;
		for (int i=1;i<=len;i++)
		{
			ans.x[i]=x[i]*tmp+c;
			c=ans.x[i]/BIT;
			ans.x[i]%=BIT;
		}
		while (c>0)
		{
			ans.x[++ans.len]=c%BIT;
			c/=BIT;
		}
		return ans;
	}
	
	inline struct prec operator * (struct prec tmp)
	{
		struct prec ans;
		int id;
		for (int i=1;i<=len;i++)
		{
			int c=0;
			for (int j=1;j<=tmp.len;j++)
			{
				ans.x[i+j-1]+=(x[i]*tmp.x[j]+c);
				c=ans.x[i+j-1]/BIT;
				ans.x[i+j-1]%=BIT;
			}
			id=i+tmp.len-1;
			while (c>0)
			{
				ans.x[++id]=c%BIT;
				c/=BIT;
			}
			ans.len=max(id,ans.len);
		}
		return ans;
	}
	
	inline struct prec operator / (int tmp)
	{
		struct prec ans;
		int c=0;ans.len=len;
		for (int i=len;i>=1;i--)
		{
			c=c*BIT+x[i];
			ans.x[i]=c/tmp;
			c%=tmp;
		}
		while (ans.x[ans.len]==0) ans.len--;
		return ans;
	}
}f[MAXN],c[MAXN][MAXN];

inline struct prec turn_prec(int tmp)
{
	struct prec ans;
	while (tmp)
	{
		ans.x[++ans.len]=tmp%BIT;
		tmp/=BIT;
	}
	return ans;
}

inline struct prec qpow(struct prec a,long long b)
{
	struct prec res;res=1;
	while (b)
	{
		if (b&1) res=res*a;
		a=a*a;b>>=1;
	}
	return res;
}

inline struct prec calc(int n)
{
	return qpow(turn_prec(2),n*(n-1)/2);
}

inline void init()
{
	c[0][0]=1;
	for (int i=1;i<=50;i++)
	{
		c[i][0]=c[i][i]=1;
		for (int j=1;j<i;j++)
			c[i][j]=c[i-1][j]+c[i-1][j-1];
	}
	f[0]=1;f[1]=1;
	for (int i=2;i<=50;i++)
	{
		f[i]=calc(i);
		for (int j=1;j<i;j++)
			f[i]=f[i]-(f[j]*c[i-1][j-1]*calc(i-j));
	}
}

int main()
{
	init();
	while (true)
	{
		n=read<int>();
		if (n==0) break;
		f[n].print('\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