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

贴错了。。。。

Posted by Leon_Xu at 2010-12-05 21:26:19 on Problem 1061
In Reply To:贴一下代码。 Posted by:Leon_Xu at 2010-12-05 21:24:33
#include <stdio.h>

int main(int argc, char* argv[])
{
    int x, y, m, n, L, dd, dv, ltimes, tmp, first;
    scanf("%d%d%d%d%d", &x, &y, &m, &n, &L);
    
    x %= L;
    y %= L;
    m %= L;
    n %= L;

    if(m>n)
    {
        dd = (x<y) ? y-x : L-(x-y);
        dv = m-n;
    }
    else if(m<n)
    {
        dd = x>y ? x-y : L-(y-x);
        dv = n-m;
    }
    else
    {
        printf("Impossible\n");
        return 0;
    }

    tmp = dd;
    ltimes = 0;
    first = 1;

    while(1)
    {
        if(tmp%dv == 0)
        {
            ltimes += (tmp/dv);
            printf("%d\n", ltimes);
            break;
        }

        if( (!first) && (tmp >= dd) && (((tmp-dd)%dv) == 0))
        {
            printf("Impossible\n");
            break;
        }

        ltimes += tmp/dv+1;
        tmp = L + (tmp%dv-dv);
        first = 0;
    }

    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