1715 Hexadecimal Numbers 给出十六进制系统,每一个16进制的数对应于一个10进制的数,16进制的数最长8位,然后按10进制从大到小排序。 首位不能为零。 给出n,要求第n大的16进制数。
2010-10-03 16:31
453 查看
Hexadecimal Numbers
Description
The base of the hexadecimal system is 16. In order to write down numbers in this system one uses 16 digits 0,1,...,9,A,B,C,D,E,F. The capital letters A,..,F stands for 10,..,15, respectively. For instance the value of the hexadecimal number CF2 is 12 * 162 + 15 * 16 + 2 = 3314 in the decimal system. Let X be the set of all positive integers whose hexadecimal representations have at most 8 digits and do not contain repetitions of any digit. The most significant digit in such a representation is not zero. The largest element in X is the number with the hexadecimal representation FEDCBA98, the second largest is the number FEDCBA97, the third is FEDCBA96 and so forth.
Write a program that: finds the n-th largest element of X;
Input
The first line of the file standard input contains integer n in the decimal representation. n does not exceed the number of elements of X.
Output
Your program should output the n-th largest element in X in the hexadecimal representation.
Sample Input
Sample Output
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 1555 | Accepted: 373 |
The base of the hexadecimal system is 16. In order to write down numbers in this system one uses 16 digits 0,1,...,9,A,B,C,D,E,F. The capital letters A,..,F stands for 10,..,15, respectively. For instance the value of the hexadecimal number CF2 is 12 * 162 + 15 * 16 + 2 = 3314 in the decimal system. Let X be the set of all positive integers whose hexadecimal representations have at most 8 digits and do not contain repetitions of any digit. The most significant digit in such a representation is not zero. The largest element in X is the number with the hexadecimal representation FEDCBA98, the second largest is the number FEDCBA97, the third is FEDCBA96 and so forth.
Write a program that: finds the n-th largest element of X;
Input
The first line of the file standard input contains integer n in the decimal representation. n does not exceed the number of elements of X.
Output
Your program should output the n-th largest element in X in the hexadecimal representation.
Sample Input
11
Sample Output
FEDCBA87
#include "iostream" #include "cstring" #include "cstdio" using namespace std; const int N = 101; #define LLD __int64 char str ; LLD dig[9],lmax; int vis ,res ; int n,m; LLD fac(int n,int m) { //p(n,m)=n(n-1)(n-2)……(n-m+1)= n!/(n-m)!(规定0!=1). if(m==0) return 1; int i,j,t; LLD cnt=1; t=n; while(1) { cnt=cnt*t; if(t==n-m+1) break; t--; } return cnt; } void solve() { int i,j,t,ud=0; LLD tmp; bool flag=false; memset(vis,0,sizeof(vis)); for(i=1;i<=8;i++)//从高位找起 { t=15;//从高找起 while(t>=1) { if(!vis[t])//每个数只能出现一次 { tmp=fac(16-1-ud,8-i);//高位已经确定时,剩下的组合有tmp种 ud表示已经有的位数 if(tmp<n)//若组合数还小于当前n的话则减去tmp继续算该位等于t--时的个数 n=n-tmp; else//否则该位就是t 标记跳出 { vis[t]=1; break; } } t--; } res[i]=t; if(t!=0||flag) ud++;//首位去0 if(t!=0) flag=true; } } void print() { int i,j; char ch; bool flag=false; for(i=1;i<=8;i++) if(res[i]!=0||flag) { if(res[i]<10) printf("%d",res[i]); else {ch='A'+res[i]-10; printf("%c",ch); } flag=true; } printf("/n"); } int main() { //cout<<fac(16,8)<<endl; while(scanf("%d",&n)!=EOF) { solve(); print(); } }
相关文章推荐
- js 解密 16进制转10进制,再取ascii码的对应值
- 10进制转16进制,16进制转10进制,随机出一个6位十六进制颜色值
- 然后程序输出它对应的2进制数 c语言程序:任意输入一个10进制数(小于255)
- ACM457现在给出了一个只包含大小写字母的字符串,不含空格和换行,要求把其中的大写换成小写,小写换成大写,然后输出互换后的字符串。输入 第一行只有一个整数m(m<=10),表示测试数据组数。
- 如何快速记住16进制中A、B、C、D、E、F对应的10进制数值
- hdu 3656 Fire station 重复覆盖 DLX+二分答案 给出一些城市及一些救火站的坐标,要求这些救火站覆盖所有的城市,问从救火站到城市的最长时间至少是多少。
- java16进制转10进制
- iOS_从APP内跳转到系统WiFi设置界面在iOS 10以上不能跳转的问题
- vc 10进制与2 8 16进制相互转换
- 【C】printf按8进制、10进制、16进制输出以及高位补0
- 16进制 10进制 BCD码之间的转换
- .net c# 进制转换 2进制、8进制、10进制、16进制
- 10进制数和16进制字符串 相互转换
- 16进制转10进制-C语言实现
- 巧借 Convert 实现 2进制 10进制 16进制 互转
- 二进制字符串和十六进制字符串转换为对应ASCII码和字符中不同进制间的转换
- 输入n个整数,编写函数实现以下操作,要求用指针实现: (1) 对n个数进行排序; (2) 将从指定位置的m个数逆序存放,例如:原序列为2,4,6,8,10,12,14,16,18,20,若要求把
- 10进制转换成16进制
- 16进制字符串转化为10进制数
- 递推: 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数 要求下排每个数都是先前上排那十个数在下排出现的次数