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 |
那位大牛能解释这个问题,俩个非常相似的程序,一个ac(0ms),一个tle!!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator