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 |
Re:这样也tle 郁闷!!!怎么能不超时阿!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator