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

坑爹呀,不知道可以用INT64过,还小写了大数结构体!!

Posted by CSUST_14 at 2013-04-22 12:18:47 on Problem 1189
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

#define N 55

struct BigInter
{
	const static int L=200;
	int Bit[L];
	int Blen;
	BigInter(int l =0)
	{
		Blen = 0;
		memset(Bit,0,sizeof(Bit));
		while(l)
		{
			Bit[Blen++] = l%10;
			l/=10;
		}
		if(Blen == 0) Blen = 1;
	}
	void Init()
	{
		Blen = 1;
		memset(Bit,0,sizeof(Bit));
	}
	void operator + (const BigInter other)
	{
		int Maxlen = max(Blen,other.Blen);
		Blen = Maxlen;
		for(int i=0;i<Maxlen;i++)
			Bit[i] += other.Bit[i];
		for(int i=0;i<Maxlen;i++)
			if(Bit[i]> 9 )
			{
				Bit[i+1] += Bit[i]/10; 
				Bit[i] %= 10;
			}
			if(Bit[Maxlen]>0) Blen = Maxlen+1;
			return ;
	}
	bool IsDivTwo()
	{
		return !(Bit[0] %2);
	}
	void operator / (const int s)
	{
		for(int i=Blen-1;i>=0;i--)
		{
			if(i!=0) Bit[i-1] += Bit[i]%2*10;
			Bit[i] /= 2;
		}
		while(Bit[Blen-1]==0&&Blen>1) Blen--;
	
	}
	void operator * (const int s)
	{
		for(int i=0;i<Blen;i++)
			Bit[i] *= 2;
		for(int i=0;i<Blen;i++)
			if(Bit[i]>9)
			{
				Bit[i+1] += Bit[i]/10;
				Bit[i] %= 10;
			}
			if(Bit[Blen]>0) Blen = Blen+1;
			return ;
	}
    void Print()
	{
		if(Bit[0]==0 && Blen==1) printf("0");
		else
		for(int i=Blen-1;i>=0;i--)
			printf("%d",Bit[i]);
	}
};
BigInter Dp[N][N];
int n,m;
char Map[N][N];

void Init()
{
	for(int i=0;i<=n+2;i++)
		for(int j=0;j<=n+2;j++)
			Dp[i][j].Init();
	Dp[0][0] = BigInter(1);
}

bool Input()
{
	if(cin>>n>>m) 
	{
		getchar();
		for(int i=1;i<=n;i++)
		{
			char tmp[100];
			gets(tmp);
			int l = strlen(tmp);
			int ll = 0;
			for(int j=0;j<l;j++)
				if(tmp[j] != ' ') Map[i][ll++] = tmp[j];
		}
		return true;
	}
	return false;
}

void solve()
{
	Init();
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++)
		{
			if(Map[i+1][j]=='*')
			{
				Dp[i+1][j].operator+(Dp[i][j]);
				Dp[i+1][j+1].operator+(Dp[i][j]);
			}
			else
			{
				BigInter B = Dp[i][j];B.operator*(2);B.operator*(2);
				Dp[i+2][j+1].operator+(B);
			}
		}
		int k=n;
		for(;k>=1;k--)
			if(Dp[n][m].IsDivTwo())
				Dp[n][m].operator/(2);
			else break;
		Dp[n][m].Print();printf("/");
		if(k>1){
		BigInter var(2);
		for(int i=1;i<k;i++)
			var.operator*(2);
		var.Print();
		}
		else printf("1");
		printf("\n");
		
}
int main()
{
	while(Input())
		solve();
	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