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 1017981912 at 2015-05-16 16:44:42 on Problem 1715
#include<cstdio>
#include<cstring>
using namespace std;

const char *ch={"0123456789ABCDEF"};
const int W[8]={486486000,540540000,545945400,546436800,546477750,546480900,546481125,546481140};
int now;
bool f[16];

int getMax()
{
	for(int i=15;i>=0;--i)
		if(f[i])return i;
	return -1;
}

int idx(int x,int next)
{
	while(next--)
	{
		--x;
		while(x>=0&&!f[x])--x;
	}
	return x;
}

int main()
{
	int n;
	while(scanf("%d",&n)==1)
	{
		memset(f,true,sizeof(f));
		int loc=1,k;
		for(k=0;n>W[k];++k);
		if(k)n-=W[k-1];
		for(int i=15;i>8+k;--i)loc*=i;
		--n;
		for(int i=k;i<8;++i)
		{
			now=idx(getMax(),n/loc);
			f[now]=false;
			n%=loc;
			loc/=15-i+k;
			printf("%c",ch[now]);
		}
		printf("\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