/**
大意: 给定16进制数的16个字母,,求第k大的数,,要求数的长度最大为8.,并且每个数互不相同。
思路: 从高到低挨个枚举,每一位能组成的排列数 ,拿最高位来说,能做成的排列数为15*A(15,len-i)
第二位 A(14,len-2)。。这样就可以找到k大的数的长度
接下来 。找第k大的数。同上理 ,挨个枚举每一位即可。。若加上该位的排列数大于k,则该位就是这个数,继续枚举下一位
**/ /** 大神思路
首先确定数字串的长度Len:从大到小枚举Len,每个Len下有15*P(15, Len-1)个数字串。每次用这个个数扣除输入的序数Count,直到序数Count将扣为负数时停止,就确定了长度Len。 然后从高位到低位,从大到小确定每位数字:设当前确定的数字为第i位,则第i位的任何一个取值,都有P(16 - (Len - i + 1), i - 1)个数字串将已确定的第1到i位作为前缀。每次用这个个数扣除输入的序数Count,直到序数Count将扣为负数时停止,就确定了当前位的数字。 注意不能有前导0。
**/
#include <iostream> using namespace std;
char num[]={'','','','','','','','','','','A','B','C','D','E','F'};
int ans[]; int Axy(int x,int y){
int res =;
if(y==)
return ;
while(y--){
res *= x;
x--;
}
return res;
} void solve(int count){
bool vis[]={},head = false;
int uselen = ,countv;
for(int i=;i<=;i++){
int cnt = ;
while(cnt){
if(!vis[cnt]){
if((countv = Axy(--uselen,-i))<count){
count -= countv;
}else{
vis[cnt] = true;
break;
}
}
cnt--;
}
ans[i] = num[cnt];
if(head||ans[i]!='') uselen++;
if(ans[i]!='') head = true;
}
} int main()
{
int cnt;
while(cin>>cnt){
bool head = false;
solve(cnt);
for(int i=;i<=;i++){
if(head||ans[i]!=''){ //去除前导0
cout<<(char)ans[i];
head = true;
}
}
if(!head) // 若全为0 ,则输出0
cout<<;
cout<<endl;
}
return ;
}

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. perl 爬虫两个技巧

    <pre name="code" class="cpp">jrhmpt01:/root/lwp# cat data.html <div cla ...

  2. Drupal7模块multiselect使用

    Drupal二次开发的时候,我们时常要使用到多选列表,但是官方默认的多选下拉列表,是在不敢恭维如下图所示: 不过难看不可怕,Drupal有两万第三方模块做支撑,只有你想不到,没有找不到的. 功夫不负有 ...

  3. AppStore被拒原因及总结

    4.5 - Apps using background location services must provide a reason that clarifies the purpose of th ...

  4. SGU 319 Kalevich Strikes Back(线段树扫描线)

    题目大意: n个矩形,将一个大矩形分成 n+1 块.矩形之间不重合,可是包括.求这n+1个矩形的面积 思路分析: 用线段树记录他们之间的父子关系.然后dfs 计算面积. 当给出的矩形上边的时候,就要记 ...

  5. objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )

    1.随机数的使用      1).arc4random() 比较精确不需要生成随即种子 使用方法 : 通过arc4random() 获取0到x-1之间的整数的代码如下: int value = arc ...

  6. SQL基础常用语法

    一.基础 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 DROP database dbname 3.说明:创建新表 create table ...

  7. BZOJ 3444: 最后的晚餐( )

    把暗恋关系看成无向边, 那某个点度数超过2就无解.存在环也是无解.有解的话对连通分量进行排列就行了. ------------------------------------------------- ...

  8. hdu 4614 Vases and Flowers 线段树

    题目链接 一共n个盒子, 两种操作, 第一种是给出两个数x, y, 从第x个盒子开始放y朵花, 一个盒子只能放一朵, 如果某个盒子已经有了, 那么就跳过这个盒子放下面的盒子. 直到花放完了或者到了最后 ...

  9. C++ 面向对象学习1

    #include "stdafx.h" #include <iostream> //不要遗漏 否则不能使用cout using namespace std; class ...

  10. Ntop监控网络流量

    运用Ntop监控网络流量 ____ 网络流量反映了网络的运行状态,是判别网络运行是否正常的关键数据,在实际的网络中,如果对网络流量控制得不好或发生网络拥塞,将会导致网络吞吐量下降. 网络性能降低.通过 ...