【HDU】 1027 Ignatius and the Princess II
来源:互联网 发布:淘宝女装夏装连衣裙 编辑:程序博客网 时间:2024/04/29 15:23
Ignatius and the Princess II
- 题目链接
- Ignatius and the Princess II
- 题目大意
给你n个数的全排列,现在让你求这n个全排列的第m小个。
- 题解
第一感觉是一个逆康托展开的问题…直接用康托展开的定义反着求就行了(写的有点麻烦)。
- 代码
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;int cos[9]={1,1,2,6,24,120,720,5040,40320};int m,n,ans[8],h,c[8],f[8];int main(){ while (scanf("%d%d",&n,&m)!=EOF) { memset(ans,0,sizeof(ans)); memset(f,0,sizeof(f)); if (n<=8) for (int i=0;i<n;i++) c[i]=i+1; else for (int i=n-7,h=0;i<=n;i++,h++) c[h]=i; h=0; for(int i=1;i<=min(n,8);i++) { int j=0,q=0,k=0,p; if (n>8) p=8-i; else p=n-i; while (j*cos[p]<m) j++; j--; m=m-j*cos[p]; while (q!=j+1) { if (!f[k]) q++; k++; } ans[h++]=c[k-1]; f[k-1]=1; } for (int i=1;i<=n-8;i++) printf("%d ",i); for (int i=0;i<h-1;i++) printf("%d ",ans[i]); printf("%d\n",ans[h-1]); } return 0;}
0 0
- hdu 1027 ignatius and the princess ii
- HDU 1027 Ignatius and the Princess II
- HDU 1027 ( Ignatius and the Princess II )
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- Ignatius and the Princess II hdu 1027
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- HDU 1027 Ignatius and the Princess II
- hdu 1027 Ignatius and the Princess II
- Windows批处理(cmd/bat)常用命令小结
- 生命游戏
- MVP on Android
- java对象传输流C/S传输对象
- 迅为4412烧写
- 【HDU】 1027 Ignatius and the Princess II
- 润乾集算报表呈现输出之变动行高列宽
- AutoCompleteTextView自动完成文本框简单介绍
- POJ 2752 Seek the Name, Seek the Fame
- 大小转换成M
- Android NDK
- Sqoop中文手册
- CSS overflow显示内容溢出
- 斐波拉契数列不一样的实现