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

n*lg(n)都能超时,求牛人指点,拜谢

Posted by nuanran at 2006-07-25 22:02:40 on Problem 2645
#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:
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