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

怎么缩短运行时间?

Posted by dexter at 2003-08-27 22:08:25 on Problem 1019
此题很简单嘛,只是提交时老是说time limit exceed
#include<stdio.h>
#include<malloc.h>
main()
{
	int t,i;
	long *a,j;
	scanf("%d",&t);//数据的组数
	a=(long *)malloc(sizeof(long)*t);
	for(i=0;i<t;i++)
	{
		scanf("%ld",a+i);
	}
	for(i=0;i<t;i++)
	{
		for(j=1;;j++)
		{
			if((j*(j+1)/2)>=*(a+i))
				break;
		}
		printf("%ld\n",*(a+i)-j*(j-1)/2);
	}
}

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