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 faononl at 2004-09-29 09:47:40 on Problem 1855
#include<iostream.h>
int mm( int a , int b)
{	
	if ( b%a == 0 ) return a ;
	else return mm(b%a,a);
}
int swap(int a ,int b)
{
	int tmp ;
	if ( a > b ) 
	{
		tmp = a ;
		a = b ;
		b = tmp ;
	}
	return mm(a,b);
}
int g[50*50*50*50] ;
void main()
{
	int coin[100];
	int n,t,first,more,height,i,less,j,k,l,m,count;
	int max,min;
	while(1)
	{
		cin >> n >> t ;
		if ( n == 0 && t == 0 ) break ;
		for( i = 0 ; i < n ; i++ )
		{
			cin >> coin[i] ;
		}
		count = 0 ;
		for( j = 0 ; j < n ; j++ )
		{
				for( k = j+1 ; k < n ; k++ )
				{
					first = coin[j]*coin[k]/swap(coin[j],coin[k]);
					for( l = k+1 ; l< n ; l++ )
					{
						first = coin[l]*first/swap(coin[l],first);
						for( m = l+1 ; m < n ; m++ )
						{
							g[count++] = coin[m]*first/swap(coin[m],first);	
						}
					}
				}
		}
		for( i = 0 ; i < t ; i++ )
		{
			cin >> height ;
			max = -1 ;
			min = 999999999;
			for( j = 0 ; j < count ;j++ )
			{
				first = g[j] ;
				more = less = int((height/first))*first ;
				if ( height != less ) more+=first ;
				if ( less > max ) max = less ;
				if ( more < min ) min = more ;
			}
			cout << max << ' ' << min << endl;
		}
	}
}
			


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