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。。。求大神帮看。。

Posted by yangyipeng_thought at 2015-07-04 19:40:34 on Problem 3252
上代码:
#include <iostream>
#include <cstdio>

using namespace std;

int C[33][33],bin[35];

int calc(int n){
	int num0=0,sum=0,i,j;
	
	bin[0]=0;
	while(n){
		bin[++bin[0]]=n&1;
		n>>=1;
	}
	
	for(i=1;i<bin[0]-1;i++)
		for(j=(i>>1)+1;j<=i;j++)
			sum+=C[i][j];
	
	for(i=bin[0]-1;i>=1;i--)
		if(bin[i])
			for(j=(bin[0]+1>>1)-num0-1;j<i;j++)
				sum+=C[i-1][j];
		else
			num0++;
	
	return sum;
}

int main(){
	int t,w,i,j;
	
	for(i=0;i<=32;i++)
		for(j=0;j<=i;j++)
			if(!j || i==j)
				C[i][j]=1;
			else
				C[i][j]=C[i-1][j-1]+C[i-1][j];
	
	cin>>t>>w;
	
	cout<<calc(w+1)-calc(t)<<endl;
	
	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