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

类似逆康托展开,根据n可以直接计算出结果。

Posted by lyyshp at 2016-05-31 14:07:29 on Problem 2956
#include <stdio.h>

int main ()
{
	int b[10] = {0, 1, 9, 72, 504, 3024, 15120, 60480, 181440};
	int a[10] = {0, 9, 90, 738, 5274, 32490, 168570, 712890, 2345850};
	int x, i, w, base, y, j;

	while( scanf( "%d", &x ) && x ){
		for( w = 1; x > a[w]; w ++ );
		x -= a[w - 1], base = b[w];
		bool m[10] = {0};
		for( i = 0; i < w; i ++ ){
			y = x / base;
			x %= base;
			if( !x ) x = base, y --;
			if( !i ) y ++;
			for( j = 0; j < 10; j ++ ){
				if( !m[j] ) y --;
				if( y < 0 ) break;
			}
			printf( "%d", j );
			m[j] = true;
			base /= 9 - i;
		}
		puts( "" );
	}
    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