| ||||||||||
| 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 | |||||||||
n*lg(n)都能超时,求牛人指点,拜谢#include <stdio.h>
int main()
{
__int64 a,b,tmp;
int f,st,ed,mid,i;
while(scanf("%I64d%I64d",&a,&b)&&(a||b))
{
if(a==b)
{
printf("2 0\n");
continue;
}
else if(a==0)
{
printf("0 2\n");
continue;
}
f=0;
for(i=2;i<=50000;i++)
{
st=1,ed=i-1;
while(st<=ed)
{
mid=(st+ed)/2;
tmp=(b-a)*mid*mid-a*(i-mid)*(i-mid)-2*a*mid*(i-mid)+a*(i-mid)-(b-a)*mid;
if(tmp>0) ed=mid-1;
else if(tmp<0) st=mid+1;
else
{
f=1;
printf("%d %d\n",mid,i-mid);
break;
}
if(f) break;
}
if(f) break;
}
if(!f) printf("impossible\n");
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator