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

Re:超时怎么回事啊 啊?????????????????

Posted by IOVE at 2011-04-13 15:04:36 on Problem 3979
In Reply To:超时怎么回事啊 啊????????????????? Posted by:IOVE at 2011-04-13 15:02:16
#include<iostream>
#include<string>

using namespace std ;

const int N = 6 ;
int A[ N ] ;

int gb( int a, int b )
{
	int x ;
	for( x = a ; x <= a*b ; x += a )
	{
		if( x % b == 0 )
			break ;
	}
	return x ;
}
int main()
{
	string a ;
	int i, j, m, n, k ;
	while( cin >> a )
	{
		j = 0 ;
		i = 0 ;
		for( i = 0 ; i < a.size() ;i++ )
		{
			if( i == 0 || i == 2 || i == 4 || i == 6 )
			{
				A[ i ] = a[ i ] - '0' ;
			}
		}
		
		if( A[ 2 ] != A[ 6 ] )
		{
			k = gb( A[ 2 ], A[ 6 ] ) ;
			m = k / A[ 2 ] ;
			n = k / A[ 6 ] ;
			A[ 0 ] = m * A[ 0 ] ;
			A[ 4 ] = n * A[ 4 ] ;
			if( a[ 3 ] == '+' )
			{
				if( k >= A[ 0 ] + A[ 4 ] )
				{
					if( k % ( A[ 0 ] + A[ 4 ] ) == 0 && ( k != A[ 0 ] + A[ 4 ] ) )
						cout << 1 << "/" << k / ( A[ 0 ] + A[ 4 ] ) ;
					else if( k % ( A[ 0 ] + A[ 4 ]) != 0 )
						cout << A[ 0 ] + A[ 4 ] << "/" << k << endl ;
					else
						cout << 1 << endl ;
				}
				else 
				{
					if( ( A[ 0 ] + A[ 4 ] ) % k == 0 )
						cout << ( A[ 0 ] + A[ 4 ] ) / k  << endl ;
					else
						cout << A[ 0 ] + A[ 4 ] << "/" << k << endl ;
				}
			}
			else if( a[ 3 ] == '-' )
			{
				if( A[ 0 ] - A[ 4 ] != 0 )
				{
					if( abs( A[ 0 ] - A[ 4 ] ) <= k )
					{
						if( k % abs( A[ 0 ] - A[ 4 ] ) == 0 && k != A[ 0 ] - A[ 4 ] )
							cout << ( A[ 0 ] > A[ 4 ] ? 1 : -1 ) << "/" << k / abs( A[ 0 ] - A[ 4 ] ) << endl ;
						else if( k % abs( A[ 0 ] - A[ 4 ] ) != 0 )
							cout << A[ 0 ] - A[ 4 ] << "/" << k << endl ;
						else if( k == A[ 0 ] - A[ 4 ] )
							cout << 1 << endl ;
					}
					else
					{
						if( abs( A[ 0 ] - A[ 4 ] ) % k == 0 )
							cout << ( A[ 0 ] - A[ 4 ] ) / k  << endl ;
						else
							cout << A[ 0 ] - A[ 4 ] << "/" << k << endl ;
					}
				}
				else if( A[ 0 ] == A[ 4 ] )
				{
					cout << 0 << endl ;
				}
			}
		}
		else if( A[ 2 ] == A[ 6 ] )
		{
			if( a[ 3 ] == '+' )
			{
				if( A[ 0 ] + A[ 4 ] <= A[ 2 ] )
				{
					if( A[ 2 ] % ( A[ 0 ] + A[ 4 ] ) == 0  && A[ 2 ] != ( A[ 0 ] + A[ 4 ] ) )
						cout << 1  << "/" << A[ 2 ] / ( A[ 0 ] + A[ 4 ] ) << endl ;
					else if( A[ 2 ] % ( A[ 0 ] + A[ 4 ] ) != 0 )
						cout << A[ 0 ] + A[ 4 ] << "/" << A[ 2 ] << endl ;
					else 
						cout << 1 << endl ;
				}
				else 
				{
					if( ( A[ 0 ] + A[ 4 ] ) % A[ 2 ] == 0 )
						cout << ( A[ 0 ] + A[ 4 ] ) / A[ 2 ] << endl ;
					else
						cout << A[ 0 ] + A[ 4 ] << "/" << A[ 2 ] << endl ;
				}
			}
			else if( a[ 3 ] == '-' )
			{
				if( A[ 0 ] != A[ 4 ] )
				{
					if( abs(A[ 0 ] - A[ 4 ]) <= A[ 2 ] )
					{
						if( A[ 2 ] % abs( A[ 0 ] - A[ 4 ] ) == 0 && A[ 2 ] != ( A[ 0 ] - A[ 4 ] ) )
							cout << ( A[ 0 ] > A[ 4 ] ? 1 : -1) << A[ 2 ] / abs( A[ 0 ] - A[ 4 ] ) << endl ;
						else if( A[ 2 ] % abs( A[ 0 ] - A[ 4 ] ) != 0 )
							cout << A[ 0 ] - A[ 4 ] << "/" << A[ 2 ] << endl;
						else if( A[ 2 ] == A[ 0 ] - A[ 4 ] )
							cout << 1 << endl ;
					}
					else if( abs( A[ 0 ] - A[ 4 ] ) >A[ 2 ] )
					{
						if( abs( A[ 0 ] - A[ 4 ] ) % A[ 2 ] == 0 )
							cout << ( A[ 0 ] - A[ 4 ] ) / A[ 2 ] << endl ;
						else
							cout << A[ 0 ] - A[ 4 ] << "/" << A[ 2 ] << endl ;
					}
				}
				else
					cout << 0 << 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