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 momo at 2006-10-27 16:35:58 on Problem 2680
#include<stdio.h>
void main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int i,j,count=0;
		int s[1005]={0};
		for(i=2;i<=n;i++)
		{
			if(i%2)
			{
				for(j=0;j<=count;j++)
				{
					s[j]*=2;
				}
				s[0]=s[0]-1;
				for(j=0;j<=count;j++)
				{
					s[j+1]+=s[j]/10;
					s[j]=s[j]%10;
				}
				if(s[j]!=0)s[++count]=s[j];
			}
			else {
				for(j=0;j<=count;j++)
				{
					s[j]*=2;
				}
				s[0]=s[0]+1;
				for(j=0;j<=count;j++)
				{
					s[j+1]+=s[j]/10;
					s[j]=s[j]%10;
				}
				if(s[j]!=0)s[++count]=s[j];
			}
		}
		for(i=count;i>=0;i--)printf("%d",s[i]);
		printf("\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