Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
无意间用unsigned long 替换了 long 搞定了 !!不信可以做个实验,下面是一个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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator