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组数据,连负数的考虑了,就是wa

Posted by lllsuper at 2009-07-15 10:01:02 on Problem 1061
#include<iostream>
using namespace std;
int main()
{
    __int64 x,y,m,n,l,v_c,s_c,w,num,i;
    int flag;
    while(cin>>x>>y>>m>>n>>l)
    {
    num=0;
    flag=0;
    x=x%l;
    y=y%l;
    if(x<0)
    x=x+l;
    if(y<0)
    y=y+l;
    if(x==y)
    {
        cout<<0<<endl;
        continue;
    }
    if(m==n)
    {
        cout<<"Impossible"<<endl;
        continue;
    }
    else if(m>n)
    v_c=m-n;
    else
    v_c=n-m;    
    if(x>y&&m>n)
    s_c=l-x+y;
    else if(x>y&&m<n)
    s_c=x-y;
    else if(x<y&&m>n)
    s_c=y-x;
    else if(x<y&&m<n)
    s_c=l-y+x;    
    for(i=0;i<1000000;i++)
    {
        w=s_c%v_c;
        num+=s_c/v_c;
        if(w==0)
        {
            flag=1;
            break;   
        }
        else
        {
            s_c=l-v_c+w;
            num++;
        }
    }
    if(flag==1)
    cout<<num<<endl;
    else
    cout<<"Impossible"<<endl;
    }
    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