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 houxuanfelix at 2006-05-14 22:29:01 on Problem 1061
#include <stdio.h>
int main()
{
    int  x,y,m,n,l;
    while (scanf ("%d%d%d%d%d",&x,&y,&m,&n,&l)!=EOF)
    {
          if (m>n)
          {
                  m=m-n;
                  x=(y-x+l)%l;
          }
          else
          {
                 m=n-m;
                 x=(x-y+l)%l;
          }
          n=x/m;
          x=x%m;
          y=x;
          while (1)
          {
              if (y==0)
              {
                  printf ("%d\n",n);
                  break;
              }
              n+=(y+l)/m;
              y=(y+l)%m;
              if (y==x)
              {
                  printf ("Impossible\n");
                  break;
              }
          }
    }
    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