题目传送门

题意:

将1~n个数按字典序排序后,求第k个数

思路:

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;
int ans;
int n,k;
bool flag;
int cnt; void dfs(int x,int &cnt)
{//cout<<x<<" "<<cnt<<endl;
if(flag) return ;
if(x>n||cnt>k) return ;
if(cnt==k) {
ans=x;
flag=;
return ;
}
for(int i=*x;i<*(x+);i++)
{
if(i>n) return ;//注意这里在hdu写成if(i<n)会超时
dfs(i,++cnt);
} }
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ans=;
scanf("%d %d",&n,&k);
cnt=;
flag=;
for(int i=;i<=;i++)
dfs(i,++cnt);
printf("%d\n",ans);
}
return ;
}

参考博客:https://www.cnblogs.com/zquzjx/p/10560280.html

最新文章

  1. wordpress 获取特色图片url方法
  2. Maximum Depth of Binary Tree
  3. Amazon Kinesis Producer Library 使用记录
  4. jdbc三种常见用法
  5. How to change Visual Studio default environment setting
  6. CSS3 背景属性
  7. 【Oracle】-【体系结构】-【DBWR】-DBWR进程相关理解
  8. PPTP支持IPv6
  9. Python的math模块
  10. [hgoi#2019/2/16t2]friend
  11. [Coding Study]——目录
  12. windows Server 2008 R2 开关机取消登录时要按Ctrl+Alt+Delete组合键登录的方法
  13. escape()、encodeURI()、encodeURIComponent()区别详解 (转)
  14. Service Fabric下删除实例并注销应用
  15. noip第6课资料
  16. python的Web框架,Django模板标签及模板的继承
  17. atom使用markdown
  18. FSM有限状态机
  19. 转载:在PHP语言中使用JSON和将json还原成数组
  20. CakePHP Configure::read(&#39;KHCITY&#39;) 数据配置读取

热门文章

  1. Apache Flink CEP 实战
  2. spring boot 配置HTTPS
  3. maven项目使用自己创建的jar包--maven without test code
  4. pyCharm报错&quot;your evaluation license has expired, pycharm will now exit&quot;解决方法(实测)
  5. [UPC10525]:Dove打扑克(暴力+模拟)
  6. hg(Mercurial)使用参考
  7. 各种sort排序总结
  8. CentOS7 修改网卡名称为eth0 & 在VMWare中添加多网卡配置
  9. MYSQL5.7源码包编译安装
  10. 函数传参和firture传参数request