题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2062
详细分析:http://mamicode.com/info-detail-95273.html
http://www.xuebuyuan.com/445957.html
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <vector> #include <set> #include <map> #define LL long long #define mod 1000000007 #define inf 1<<30 #define N 2010 using namespace std; LL a[100],b[100]; void init() { a[1]=1; for(int i=2;i<=20;i++)a[i]=(a[i-1]+1)*i; } int main() { LL n,m; init(); while(scanf("%I64d%I64d",&n,&m)>0) { for(int i=1;i<=n;i++)b[i]=i; while(m!=0) { int t=m/(a[n]/n)+(m%(a[n]/n)?1:0); printf("%d",b[t]); m-=(a[n]/n)*(t-1)+1; if(m)printf(" "); for(int i=t;i<n;i++)b[i]=b[i+1]; n--; } puts(""); } }