hdu6468 zyb的面试 (思维)
2024-09-05 19:31:12
题意:
将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
最新文章
- wordpress 获取特色图片url方法
- Maximum Depth of Binary Tree
- Amazon Kinesis Producer Library 使用记录
- jdbc三种常见用法
- How to change Visual Studio default environment setting
- CSS3 背景属性
- 【Oracle】-【体系结构】-【DBWR】-DBWR进程相关理解
- PPTP支持IPv6
- Python的math模块
- [hgoi#2019/2/16t2]friend
- [Coding Study]——目录
- windows Server 2008 R2 开关机取消登录时要按Ctrl+Alt+Delete组合键登录的方法
- escape()、encodeURI()、encodeURIComponent()区别详解 (转)
- Service Fabric下删除实例并注销应用
- noip第6课资料
- python的Web框架,Django模板标签及模板的继承
- atom使用markdown
- FSM有限状态机
- 转载:在PHP语言中使用JSON和将json还原成数组
- CakePHP Configure::read(&#39;KHCITY&#39;) 数据配置读取
热门文章
- Apache Flink CEP 实战
- spring boot 配置HTTPS
- maven项目使用自己创建的jar包--maven without test code
- pyCharm报错";your evaluation license has expired, pycharm will now exit";解决方法(实测)
- [UPC10525]:Dove打扑克(暴力+模拟)
- hg(Mercurial)使用参考
- 各种sort排序总结
- CentOS7 修改网卡名称为eth0 & 在VMWare中添加多网卡配置
- MYSQL5.7源码包编译安装
- 函数传参和firture传参数request