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++)

Posted by chnegzi at 2008-04-06 22:13:01 on Problem 1061
In Reply To:二十几次了,还是错误,哪位大侠帮忙看看(G++) Posted by:richardlee at 2008-03-18 21:27:25
#include <stdio.h>
__int64 x;
__int64 y;
__int64 m;
__int64 n;
__int64 L;
__int64 times;

bool caculate( __int64 pos, __int64 rate, __int64 L);

bool doit( __int64 x, __int64 y, __int64 m, __int64 n, __int64 L)
{
    __int64 rate;
    __int64 pos;
    
    if(x==y ||x <0||y <0||
        x>=   2000000000||
        y>=   2000000000||
        m>=   2000000000||
        n>=   2000000000||
        L>=   2100000000||
        m <=0 || n <=0 || m==n || L <=0)
    {
        return false;
    }

    x%=L;
    y%=L;
    if(x==y)
    {
        return false;
    }
    m%=L;
    n%=L;
    if(m==n)
    {
        return false;
    }
    if(m>n)                // A的速度快
    {
        rate=m-n;
        if(y>x)
        {
            pos=y-x;
        }
        else
        {
            pos=y+L-x;
        }
    }
    else
    {
        rate=n-m;
        if(x>y)
        {
            pos=x-y;
        }
        else
        {
            pos=x+L-y;
        }
    }

    if(rate>L/2)         //从末端来追,可以减少循环的次数
    {
        return caculate(L-pos,L-rate,L);
    }
    else
    {
        return caculate(pos,rate,L);
    }
}

bool caculate( __int64 pos, __int64 rate, __int64 L)
{
    if(L%2==0 && pos%2==1 && rate%2==0)
    {
        return false;
    }

    if(pos%rate!=0 && L%rate==0)
    {
        return false;
    }
    __int64 c=pos%rate;
    __int64 d = pos;
    __int64 e=d%rate;
    while(e!= 0)
    {
        d += L;
        e=d%rate;
        if(e==c)
        {
            return false;
        }
    }
    times = d/rate;
    return true;
}


int main(void)
{
    scanf("%d %d %d %d %d",&x, &y, &m, &n, &L);

    if( doit( x, y, m, n, L))
    {
        printf("%ld\n",times);
    }
    else
    {
        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