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 ppp at 2004-12-28 17:52:53 on Problem 2081
In Reply To:求助:怎么才能不超时阿…… Posted by:Amethyst at 2004-12-28 17:19:28
> #include<stdio.h>
> void main()
> {
> 	int n,i,j;
> 	int a[100000];
> 	
> 	scanf("%d",&n);
> 	while(n!=-1)
> 	{
> 		a[0] = 0;
> 		for(i=1;i<=n;i++)
> 		{
> 			a[i] = a[i-1] - i;
> 			if(a[i]<=0)
> 			{
> 				a[i] = a[i] + 2*i;
> 				continue;
> 			}
> 			j=0;
> 			while(j<i)
> 			{
> 				if(a[i]==a[j])
> 				{
> 					a[i] = a[i] + 2*i;
> 					break;
> 				}
> 				j++;
> 			}
> 		}
>     	printf("%d\n",a[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