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,跟ac程序对拍都没问题

Posted by 2008__ at 2008-08-07 22:52:14 on Problem 3252
#include<stdio.h>

__int64 c[33]={0};

int binary(long n,int bin[33])
{
	int t[33];
	int i;
	int L;
	L=0;
	while(n!=0)
	{
		t[L++]=n%2;
		n/=2;
	}
	for(i=0;i<L;i++)
	{
		bin[i]=t[L-i-1];
	}
	return L;
}

__int64 Cmn(int m,int n)
{
	__int64 count;
	int i;
	if(m==0||m<n)
		return 0;
	if(n==0)
		return 1;
	count=m;
	for(i=1;i<n;i++)
	{
		count=count*(m-i)/i;
	}
	count/=i;
	return count;
}

__int64 sub(long N)
{
	int bin[33];
	int one;
	int L;
	int i,j;
	int m,n;
	__int64 count;
	L=binary(N,bin);
	count=c[L];
	one=0;
	for(i=0;i<L;i++)
	{
		if(bin[i]==1)
		one++;
		if(bin[i]==0)
		{
			m=L-i-1;
			n=L/2-one-1;
			if(n>=0)
			{
				for(j=0;j<=n;j++)
				{
					count-=Cmn(m,j);					
				}
			}
		}
	}
	if(n>=0&&bin[L-1]==0)count--;
	return count;
}

int main()
{
	long a,b;
	__int64 r;
	__int64 count;
	int i,j;
	for(i=2;i<32;i++)
	{
		count=0;
		for(j=0;j<i/2;j++)
		{
			count+=Cmn(i-1,j);
		}
		c[i]=c[i-1]+count;
	}
	while(scanf("%ld%ld",&a,&b)!=EOF)
	{
        r=sub(b)-sub(a-1);
		printf("%ld\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