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

无意间用unsigned long 替换了 long 搞定了 !!

Posted by 200593141 at 2007-07-13 14:41:19 on Problem 1061
不信可以做个实验,下面是一个AC程序,如将第一行unsigned long 改为 long,立即变为WA,
能否有人说明其原因???
#include<iostream>
using namespace std ;

void main()
{
   unsigned long x, y, m, n, L ;  
   int Skipdistance, distance ;  
   cin >> x >> y >> m >> n >> L ;   
   if( m > n )
   {
      Skipdistance = m - n ;
	  distance = ( y - x + L ) % L ;
   }
   else if( m < n )
   {
      Skipdistance = n - m ;
	  distance = ( x - y + L ) % L ;
   }
   else
   {
     cout << "Impossible\n" ;
	 return ; 
   }
   
   int steps = distance / Skipdistance ;
   distance %= Skipdistance ;
   int beginned = distance ;

   while( true )
   {
	   if( distance == 0 )
	  {
	     cout << steps << endl ;
		 break ;
	  }

      steps += ( distance + L ) / Skipdistance ;
	  distance = ( distance + L ) % Skipdistance ;
	  
	  if( distance == beginned )
	  {
		 cout << "Impossible\n" ;
		 break ;
	  }
   }
}

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