| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么我用G++会超时?C++就是15MS,用二分来写的,应该不会超时啊?请高手指点#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator