同样是确定某位上的数,当确定某一位后,其后面的排列数是确定的,所以可以用除法和取余数的方法来确定这一位的值

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; int lim[10];
bool vis[20];
int ans[20],ansl;
void initial(){
lim[9]=0;
lim[8]=486486000;
lim[7]=540540000;
lim[6]=545945400;
lim[5]=546436800;
lim[4]=546477750;
lim[3]=546480900;
lim[2]=546481125;
lim[1]=546481140;
} int judge(int &n){
for(int i=8;i>=1;i--){
if(n<=lim[i]){
n=n-lim[i+1];
return i;
}
}
} int getnum(int bt,int hw){
int sum=1;
for(int i=hw;i>0;i--){
sum=sum*bt;
bt--;
}
return sum;
} void enAns(int w){
for(int i=15;i>=0;i--){
if(w==0){
if(!vis[i]){
ans[ansl++]=i;
vis[i]=true;
return ;
}
else{
continue;
}
}
else{
if(!vis[i]){
w--;
}
else{
continue;
}
}
}
} void work(int num,int hw){
int bt=16;
int tmp,word;
for(int i=hw-1;i>=0;i--){
bt--;
tmp=getnum(bt,i);
word=num/tmp;
// cout<<word<<endl;
num%=tmp;
enAns(word);
}
} int main(){
initial();
int n;
while(scanf("%d",&n)!=EOF){
memset(vis,false,sizeof(vis));
ansl=0;
if(n==546481141){
printf("0\n");
continue;
}
int hw=judge(n);
n--;
// cout<<hw<<endl;
work(n,hw);
for(int i=0;i<ansl;i++){
if(ans[i]>=10){
printf("%c",ans[i]-10+'A');
}
else printf("%c",ans[i]+'0');
}
printf("\n");
}
return 0;
}

  

POJ 1715的更多相关文章

  1. poj 1715 Hexadecimal Numbers 排列组合

    /** 大意: 给定16进制数的16个字母,,求第k大的数,,要求数的长度最大为8.,并且每个数互不相同. 思路: 从高到低挨个枚举,每一位能组成的排列数 ,拿最高位来说,能做成的排列数为15*A(1 ...

  2. JAVA大数--POJ 1715 大菲波数

    Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值.  Inp ...

  3. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  4. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  5. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  6. 转载:poj题目分类(侵删)

    转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码)  ...

  7. POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

    题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...

  8. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  9. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

随机推荐

  1. 一点一点学架构(四)—Spring.NET错误Cannot Resolve Type……

    背景 在搭建完项目框架之后,当我利用单元測试来測一条线时.出现了下面错误: Cannot resolve type[--]for object with name 'ButtonBll' define ...

  2. TCP打洞技术

    //转http://iamgyg.blog.163.com/blog/static/3822325720118202419740/ 建立穿越NAT设备的p2p的TCP连接仅仅比UDP复杂一点点,TCP ...

  3. Struts2值栈的相关操作

    import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext; import ...

  4. 2015.04.28,外语,读书笔记-《Word Power Made Easy》 12 “如何奉承朋友” SESSION 36

    1. the great and the small 拉丁词语animus(mind的意思),animus和另一个拉丁词根anima(life principle.soul.spirit),是许多单词 ...

  5. linux下安装redis3.2

    这部分来自网络: http://blog.csdn.net/cuibruce/article/details/53501532 1.下载 下载地址:http://www.redis.io/downlo ...

  6. MySql悲观锁总结与实践

    mysql(for update)悲观锁总结与实践 https://blog.csdn.net/zmx729618/article/details/52701972 悲观锁,正如其名,它指的是对数据被 ...

  7. Windows下Word.exe在哪?

    在这里: C:\Program Files\Microsoft Office\root\Office16

  8. CLR - 设计类型

    前言 好记性不如烂“笔头”系列... 目录 类型基础 基元类型.引用类型和值类型 类型与成员 常量与字段 方法 类型基础 “运行时”要求每个类型最终都从System.Object 类型派生. 由于所有 ...

  9. 读书笔记之《HTML5 与 CSS3 基础教程》

    1· 读前预期 考虑到对于 Web 开发零基础,凡涉足一件未知的任务,最好先理清任务的逻辑结构,然后有目的地逐步学习.为实现我们的需求和设计,必须要学习前端.后端.服务器等一系列暂时陌生的知识,在此, ...

  10. SSH 项目中 用Hibernate底层 简单的封装DAO层

    废话不多少了,主要是使用hibernate的查询方法,自己封装了DAO层,供service来方便使用. 首先:必须要继承的 public class CommonDao extends Hiberna ...