1. /**
  2. 大意: 给定16进制数的16个字母,,求第k大的数,,要求数的长度最大为8.,并且每个数互不相同。
  3. 思路: 从高到低挨个枚举,每一位能组成的排列数 ,拿最高位来说,能做成的排列数为15*A(15,len-i)
  4. 第二位 A(14,len-2)。。这样就可以找到k大的数的长度
  5. 接下来 。找第k大的数。同上理 ,挨个枚举每一位即可。。若加上该位的排列数大于k,则该位就是这个数,继续枚举下一位
  6. **/
  7.  
  8. /** 大神思路
  9. 首先确定数字串的长度Len:从大到小枚举Len,每个Len下有15*P(15, Len-1)个数字串。每次用这个个数扣除输入的序数Count,直到序数Count将扣为负数时停止,就确定了长度Len。
  10.  
  11. 然后从高位到低位,从大到小确定每位数字:设当前确定的数字为第i位,则第i位的任何一个取值,都有P(16 - (Len - i + 1), i - 1)个数字串将已确定的第1到i位作为前缀。每次用这个个数扣除输入的序数Count,直到序数Count将扣为负数时停止,就确定了当前位的数字。
  12.  
  13. 注意不能有前导0。
  14. **/
  15. #include <iostream>
  16.  
  17. using namespace std;
  18. char num[]={'','','','','','','','','','','A','B','C','D','E','F'};
  19. int ans[];
  20.  
  21. int Axy(int x,int y){
  22. int res =;
  23. if(y==)
  24. return ;
  25. while(y--){
  26. res *= x;
  27. x--;
  28. }
  29. return res;
  30. }
  31.  
  32. void solve(int count){
  33. bool vis[]={},head = false;
  34. int uselen = ,countv;
  35. for(int i=;i<=;i++){
  36. int cnt = ;
  37. while(cnt){
  38. if(!vis[cnt]){
  39. if((countv = Axy(--uselen,-i))<count){
  40. count -= countv;
  41. }else{
  42. vis[cnt] = true;
  43. break;
  44. }
  45. }
  46. cnt--;
  47. }
  48. ans[i] = num[cnt];
  49. if(head||ans[i]!='') uselen++;
  50. if(ans[i]!='') head = true;
  51. }
  52. }
  53.  
  54. int main()
  55. {
  56. int cnt;
  57. while(cin>>cnt){
  58. bool head = false;
  59. solve(cnt);
  60. for(int i=;i<=;i++){
  61. if(head||ans[i]!=''){ //去除前导0
  62. cout<<(char)ans[i];
  63. head = true;
  64. }
  65. }
  66. if(!head) // 若全为0 ,则输出0
  67. cout<<;
  68. cout<<endl;
  69. }
  70. return ;
  71. }

poj 1715 Hexadecimal Numbers 排列组合的更多相关文章

  1. POJ 3252 Round Numbers(组合)

    题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...

  2. light oj 1095 - Arrange the Numbers排列组合(错排列)

    1095 - Arrange the Numbers Consider this sequence {1, 2, 3 ... N}, as an initial sequence of first N ...

  3. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  4. (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)

    /* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...

  5. poj 3761 bubble sort (排列组合)

    #include<cstdio> #include<cstring> #define ll long long #define mod 20100713 ; ll a[maxn ...

  6. POJ 3421 X-factor Chains (因式分解+排列组合)

    题意:一条整数链,要求相邻两数前一个整除后一个.给出链尾的数,求链的最大长度以及满足最大长度的不同链的数量. 类型:因式分解+排列组合 算法:因式分解的素因子个数即为链长,链中后一个数等于前一个数乘以 ...

  7. [leetcode] 题型整理之排列组合

    一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...

  8. 2017ACM暑期多校联合训练 - Team 1 1006 HDU 6038 Function (排列组合)

    题目链接 Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m ...

  9. csu 1801(合数分解+排列组合)

    1801: Mr. S’s Romance Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 15  Solved: 5[Submit][Status][W ...

随机推荐

  1. ubuntu openStack icehouse dashboard theme自定义

    1,ubuntu openStack 语言包locate

  2. WebRTC学习笔记_Demo收集

    1.     WebRTC学习 1.1   WebRTC现状 本人最早接触WebRTC是在2011年底,那时Google已经在Android源代码中增加了webrtc源代码,放在/external/w ...

  3. HDU 11488 Hyper Prefix Sets (字符串-Trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

  4. HDU5280 Senior&#39;s Array(简单DP)

    题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...

  5. Java调用R——rJava的安装和配置

    rJava是Java通过JRI调用R所要安装的包.配置起来比较麻烦,我参考网上进行配置,使用rJava包中example里面的示例测试,控制台显示: Cannot find JRI native li ...

  6. JS学习之闭包的理解

    一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量.另 ...

  7. java json的处理

    maven依赖 <dependencies> <dependency> <groupId>com.alibaba</groupId> <artif ...

  8. 使用 dotnet watch 开发 ASP.NET Core 应用程序

    使用 dotnet watch 开发 ASP.NET Core 应用程序 原文:Developing ASP.NET Core applications using dotnet watch作者:Vi ...

  9. LintCode-两个字符串是变位词

    题目描述: 写出一个函数 anagram(s, t) 去判断两个字符串是否是颠倒字母顺序构成的 样例 给出 s="abcd",t="dcab",返回 true ...

  10. C#使用系统的“显示桌面”功能(Shell.Application)

    原文 C#使用系统的“显示桌面”功能(Shell.Application) 在 Windows 系统的 任务栏 上的 快速启动栏 里,通常有一个图标  ,点击这个图标,就会切换到桌面.这个图标实际是一 ...