poj 1715 Hexadecimal Numbers 排列组合
/**
大意: 给定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 排列组合的更多相关文章
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- light oj 1095 - Arrange the Numbers排列组合(错排列)
1095 - Arrange the Numbers Consider this sequence {1, 2, 3 ... N}, as an initial sequence of first N ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)
/* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- poj 3761 bubble sort (排列组合)
#include<cstdio> #include<cstring> #define ll long long #define mod 20100713 ; ll a[maxn ...
- POJ 3421 X-factor Chains (因式分解+排列组合)
题意:一条整数链,要求相邻两数前一个整除后一个.给出链尾的数,求链的最大长度以及满足最大长度的不同链的数量. 类型:因式分解+排列组合 算法:因式分解的素因子个数即为链长,链中后一个数等于前一个数乘以 ...
- [leetcode] 题型整理之排列组合
一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...
- 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 ...
- csu 1801(合数分解+排列组合)
1801: Mr. S’s Romance Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 15 Solved: 5[Submit][Status][W ...
随机推荐
- JAVA GUI学习 - JPopupMenu鼠标右键菜单组件学习
public class JPopmenuKnow { public void test() { //为表格添加鼠标右键菜单 JMenuItem jMenuItemFileInfo = new JMe ...
- Windows Latex 中日文字体设置例
中文字体例: \documentclass[CJK]{article} \usepackage{CJKutf8} \newcommand{\songti}{\CJKfamily{song}} % 宋体 ...
- Android二维码开源项目zxing用例简化和生成二维码、条形码
上一篇讲到:Android二维码开源项目zxing编译,编译出来后有一个自带的測试程序:CaptureActivity比較复杂,我仅仅要是把一些不用的东西去掉,用看起来更方便,二维码和条形码的流行性自 ...
- MSSQL随机数概率测试
随机概率测试 创建一个表统计create table t_test(ip char(15)) --truncate table t_test; declare @i int ;set @i=0; -- ...
- [LeetCode]题解(python):002-Add Two Numbers
题目来源: https://leetcode.com/problems/add-two-numbers/ 题意分析: 这道题目是要将两个单链条相加.输出得到的新链条. 题目思路: 不难发现,其实题目就 ...
- html常用标签有哪些?
html看似复杂,其实常用的标签并不多,这里总共介绍一些html的常用标签 文字处理: ①标题:<h1> to <h6> ②段落:<p>文字段落</p> ...
- Http报文格式学习及Get和Post主要区别总结
HTTP(HyperText Transport Protocol,超文本传送协议) http请求数据包的格式:头部(request line + header)+ 数据(data) 头部和数据包体 ...
- 使用HISTCONTROL强制history忽略某条特定命令
http://www.linuxnote.org/mandatory-use-of-histcontrol-ignore-a-certain-specific-command-history.html ...
- Oracle select into from 和 insert into select
select into from SQLSERVER 创建表: select * into aaa from bbb Oracle 创建表: create table aaa as select * ...
- [C++ Basic] Const 用法
定义: const 主要用于声明常量.当常量为对象时,对象值不可改变:当常量为指针时,该指针不可移动或重新赋值,但我们可以通过它去修改该指针的指向对象的值(前提是无需移动指针的修改).所谓的形参.返回 ...