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

太难了,nlogn都严重超时

Posted by tdzl2003 at 2005-08-28 23:18:15 on Problem 2591
//TLE

#include <iostream>
#include <memory>
using namespace std;
int a[10000000],al,i;

int GetID(int n)
{
	int j,k,l;
	j=-1;k=i;
	while (j<k-1)
	{
		l=(j+k)/2;
		if (a[l]==n) return 0;
		if (a[l]>n) k=l;
		else j=l;
	}
	return k+1;
}


int main()
{
	int j;
	a[0]=1;al=1;
	for (i=1,j=1;i<10000000;i++)
	{
		for (j++;;j++)
		{
			if (j%2==1 && !GetID(j/2)) break;
			if (j%3==1 && !GetID(j/3)) break;
		}
		a[i]=j;
	}
	while (cin>>i)
		cout<<a[i-1]<<endl;
}

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