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

what's wrong? (code here)

Posted by gemenhao at 2006-03-18 22:34:13 on Problem 2613
#include<math.h>
#include<stdio.h>

double logab(int beg, int end)
{
	__int64 static max = pow(10.0,18);
	double r = 0.0;
	while(beg<=end)
	{
		__int64 temp = 1;
		while(((double)temp)*beg<max && beg<=end)
			temp *= beg++;
		r += log(temp);
	}
	return r;
}

double pqrs(int p,int q,int r,int s)
{
	int pb = (q<p/2)?q:p-q;
	int rb = (s<r/2)?s:r-s;
	double ex = 0;
	if(p>r)
	{
		if(p-pb<r-rb)
			ex = logab(r+1,p)+logab(p-pb+1,r-rb);
		else
			ex = logab(r+1,p)-logab(r-rb+1,p-pb);
	}
	else
	{
		if(p-pb>r-rb)
			ex = -logab(p+1,r)-logab(r-rb+1,p-pb);
		else
			ex = -logab(p+1,r)+logab(p-pb+1,r-rb);
	}
	if(rb<pb)
		ex -= logab(rb+1,pb);
	else
		ex += logab(pb+1,rb);

	return exp(ex);
}

int main()
{
	int p,q,r,s;
	while (scanf("%d%d%d%d",&p,&q,&r,&s)==4)
	{
		double R = pqrs(p,q,r,s);
		if(R<1000000000)
			printf("%.5f\n",R);
	}
	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