Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:n*lg(n)都能超时，求牛人指点，拜谢

Posted by nuanran at 2006-07-25 23:03:26 on Problem 2645
In Reply To:n*lg(n)都能超时，求牛人指点，拜谢 Posted by:nuanran at 2006-07-25 22:02:40
```UP
#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: