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 ...
随机推荐
- ubuntu openStack icehouse dashboard theme自定义
1,ubuntu openStack 语言包locate
- WebRTC学习笔记_Demo收集
1. WebRTC学习 1.1 WebRTC现状 本人最早接触WebRTC是在2011年底,那时Google已经在Android源代码中增加了webrtc源代码,放在/external/w ...
- 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 ...
- HDU5280 Senior's Array(简单DP)
题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...
- Java调用R——rJava的安装和配置
rJava是Java通过JRI调用R所要安装的包.配置起来比较麻烦,我参考网上进行配置,使用rJava包中example里面的示例测试,控制台显示: Cannot find JRI native li ...
- JS学习之闭包的理解
一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量.另 ...
- java json的处理
maven依赖 <dependencies> <dependency> <groupId>com.alibaba</groupId> <artif ...
- 使用 dotnet watch 开发 ASP.NET Core 应用程序
使用 dotnet watch 开发 ASP.NET Core 应用程序 原文:Developing ASP.NET Core applications using dotnet watch作者:Vi ...
- LintCode-两个字符串是变位词
题目描述: 写出一个函数 anagram(s, t) 去判断两个字符串是否是颠倒字母顺序构成的 样例 给出 s="abcd",t="dcab",返回 true ...
- C#使用系统的“显示桌面”功能(Shell.Application)
原文 C#使用系统的“显示桌面”功能(Shell.Application) 在 Windows 系统的 任务栏 上的 快速启动栏 里,通常有一个图标 ,点击这个图标,就会切换到桌面.这个图标实际是一 ...