Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
类似逆康托展开,根据n可以直接计算出结果。#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator