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 |
dp可过,485ms,小心開double数组会MLE。。。MLE: #include <iostream> #include <stdio.h> #include <cmath> using namespace std; double ans[10000010]; int mx = 0; int main() { ans[0] = 0; int t; scanf("%d", &t); for(int i = 0; i < t; i++){ int n; scanf("%d", &n); if(n <= mx){ printf("%d\n", (int)ans[n]+1); continue; } for(int i = mx+1; i <= n; i++){ ans[i] = ans[i-1] + log10(i+0.0); } mx = n; printf("%d\n", (int)ans[n]+1); } return 0; } AC: #include <iostream> #include <stdio.h> #include <cmath> using namespace std; int ans[10000010]; int main() { ans[0] = 0; double sum = 0; for(int i = 1; i <= 10000000; i++){ sum += log10(i+0.0); ans[i] = (int)sum; } //cout << 1 << endl; int t; scanf("%d", &t); for(int i = 0; i < t; i++){ int n; scanf("%d", &n); printf("%d\n", ans[n]+1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator