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

从过1338的大牛那里学到的解法... 很牛叉,直接水过(附上代码)

Posted by __24__ at 2010-08-17 09:15:06 on Problem 2591
#include<stdio.h>
#define Min(a, b) ((a)<(b)?(a):(b))
#define N 10000001
long f[N];
int main()
{
	int n,i;
	int x_2 = 1,x_3 = 1;
	f[x_2] = 1;
	f[x_3] = 1;
	for(i=2; i<=10000000; i++)
	{
		f[i] = Min(f[x_2]*2+1, f[x_3]*3+1);
		
		if(f[i] == f[x_2]*2+1)
			x_2++;
		if(f[i] == f[x_3]*3+1)
			x_3++;
	}
	while(scanf("%d",&n) != EOF)
	{
		printf("%ld\n",f[n]);
	}
	return 0;
}

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