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

开大数组,利用数组设用过的数值为1,避免查找。。这些都用了。可还是运行错误。给个可行方案,谢谢了大侠。。

Posted by jjh at 2005-08-05 15:55:03 on Problem 2081
#include<stdio.h>
void main()
{
     int m[500001];
     bool n[12000000];
     long i,j;

	m[0]=0;
	n[0]=true;

	for(i=0;i<12000000;i++)
		n[i]=false;
	for(i=1;i<=500000;i++)
	{
		if((m[i-1]-i)>0&&n[m[i-1]-i]==false)
		{m[i]=m[i-1]-i;  n[m[i]]=true;}
		else  
		{m[i]=m[i-1]+i; n[m[i]]=true;}
	}
	while(1)
		{
		scanf("%ld",&j);
		if(j==-1)  break;
		printf("%ld\n",m[j]);
		}
}


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