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

dp可过,485ms,小心開double数组会MLE。。。

Posted by KatrineYang at 2016-09-30 23:18:10 on Problem 1423
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:
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