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

那位大牛能解释这个问题,俩个非常相似的程序,一个ac(0ms),一个tle!!!

Posted by 2004huangyimin at 2006-04-25 14:08:21 on Problem 1942
Source

Problem Id:1942  User Id:2004huangyimin 
Memory:48K  Time:1015MS
Language:C++  Result:Time Limit Exceed

Source 

#include < iostream >
using namespace std;
unsigned int com (unsigned int n,unsigned int m)
{
	double i;
	double result(1);
	if ( n >= m - n ){ n = m-n; }
	for ( i = m;i >= m-n+1;i-=1 )
	{
		result *= (i / (i - (m - n)));
	}
	return result;
}
int main()
{
	unsigned int n,m;
	while (1)
	{
		scanf("%d%d",&n,&m);
		if ( n==0 && m==0 ){ break; }
		printf("%d\n",com (n,m+n));
	}
	return 0;
}

Source

Problem Id:1942  User Id:2004huangyimin 
Memory:56K  Time:0MS
Language:C++  Result:Accepted

Source 

#include < iostream >
using namespace std;
double com (double n,double m)
{
	double i;
	double result(1);
	if ( n >= m - n ){ n = m-n; }
	for ( i = m;i >= m-n+1;i-=1 )
	{
		result *= (i / (i - (m - n)));
	}
	return result;
}
int main()
{
	double n,m;
	while (1)
	{
		scanf("%lf%lf",&n,&m);
		if ( n==0 && m==0 ){ break; }
		printf("%.0lf\n",com (n,m+n));
	}
	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