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:这样也tle 郁闷!!!怎么能不超时阿!!

Posted by first at 2003-12-13 19:17:19 on Problem 1423
In Reply To:这个题目 如果都算出来的话,精确统计可是超时了阿代码如下 应该怎么做阿, Posted by:first at 2003-12-13 16:54:05
#include <iostream>
using namespace std;
void main()
{
	long double ans;
	int n,times,i,digits;
	cin>>times;
	while(times--)
	{
		cin>>n;
		ans=1.0;
		digits=0;
		for(i=2;i<=n;i++)
		{
			ans*=i;
			if(ans>=10000000.0)
			{
				digits+=7;
				ans/=10000000.0;
			}
			else if(ans>=1000000.0)
			{
				digits+=6;
				ans/=1000000.0;
			}
		    else if(ans>=100000.0)
			{
				digits+=5;
				ans/=100000.0;
			}
		 else if(ans>=10000.0)
			{
				digits+=4;
				ans/=10000.0;
			}
			else if(ans>=1000.0)
			{
				digits+=3;
				ans/=1000.0;
			}
		else	if(ans>=100.0)
			{
				digits+=2;
				ans/=100.0;
			}
		else	if(ans>=10.0)
			{
				digits+=1;
				ans/=10.0;
			}
		
		}
		digits++;
		cout<<digits<<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