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

TLE了!怎么才能提高运算速度啊?有什么简便方法看出没出现过么?

Posted by fantasyan at 2005-01-11 15:30:07 on Problem 2081
#include<stdio.h>
#include<math.h>
int num[500000];
void main(){
	int n,i,j;
	scanf("%d",&n);
	while(n!=-1){
	num[0]=0;
	for(i=1;i<=n;i++){
		num[i]=num[i-1]-i;
			if(num[i]<0)
				num[i]=num[i-1]+i;
			else for(j=0;j<i;j++)
				if(num[i]==num[j]){
					num[i]=num[i-1]+i;
					break;
				}
	}
	printf("%d\n",num[n]);
	scanf("%d",&n);
	}
}

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