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

Re:为什么我用G++会超时?C++就是15MS,用二分来写的,应该不会超时啊?请高手指点

Posted by JeeWin at 2006-08-01 16:53:20 on Problem 2309
In Reply To:为什么我用G++会超时?C++就是15MS,用二分来写的,应该不会超时啊?请高手指点 Posted by:381528779 at 2006-07-18 21:04:23
> #include<stdio.h>
> 
> __int64 a[33];
> 
> int main()
> {
> 	__int64 num,i,low,high,mid,t;
> 	for(i=0;i<33;i++)
> 		a[i]=1<<i;
> 	scanf("%I64d",&t);
> 	while(t--)
> 	{
> 		scanf("%I64d",&num);
> 
> 		for(i=0;i<32&&a[i]<num;i++)
> 			;
> 		if(a[i]==num)
> 		{
> 			printf("1 %I64d\n",a[i+1]-1);
> 			continue;
> 		}
> 		low=a[i-1],high=a[i];
> 		while(low<=high)
> 		{
> 			mid=(low+high)>>1;
> 			if(mid>num)
> 				high=mid;
> 			else
> 				if(mid<num)
> 					low=mid;
> 				else
> 					break;
> 		}
> 		if(mid%2==1)
> 		{
> 			printf("%I64d %I64d\n",mid,mid);
> 		}
> 		else
> 			printf("%I64d %I64d\n",low+1,high-1);
> 			
> 
> 	}
> 	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