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

呜呜~好郁闷,那里错了啊?知道的回信啊,谢谢!

Posted by myi_i at 2004-10-26 21:24:30 on Problem 1945
#include"stdio.h"
#include"math.h"
int flag=1;
int fun(int p)
{
	unsigned int i,m,n,inv,temp;
	temp=p;
	//printf("p=%d,",p);
	for(i=0,m=0,n=0;i<16;i++)
	{if(1==p%2){m++;n=i;}p=p>>1;}
	//printf("m=%u,n=%u,",m,n);
	if(m==1 && flag==1){return n;}
	if(flag==1){flag++;}
	if(m==1 && flag!=1)return 1;

	inv=fun((int)pow(2,n+1)-temp);
	//printf("inv=%d\n",inv);

	if(m-1>1+inv)
	{return n+inv+1;}
	else
	{return n+m-1;}
}
main()
{
	int p;
	while(scanf("%d",&p)!=EOF)
	{
		printf("%d\n",fun(p));
		flag=1;
	}
}

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