HDU 1027:Ignatius and the Princess II ← next_permutation()
【题目来源】
http://acm.hdu.edu.cn/showproblem.php?pid=1027
【题目描述】
Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5166 says, "I have three question for you, if you can work them out, I will release the Princess, or you will be my dinner, too." Ignatius says confidently, "OK, at last, I will save the Princess."
"Now I will show you the first problem." feng5166 says, "Given a sequence of number 1 to N, we define that 1,2,3...N-1,N is the smallest sequence among all the sequence which can be composed with number 1 to N(each number can be and should be use only once in this problem). So it's easy to see the second smallest sequence is 1,2,3...N,N-1. Now I will give you two numbers, N and M. You should tell me the Mth smallest sequence which is composed with number 1 to N. It's easy, isn't is? Hahahahaha......"
Can you help Ignatius to solve this problem?
【题目大意】
给定 N 和 M。
若第一个序列为 1,2,3...N-1,N,第二个序列为 1,2,3...N,N-1,……。求第 M 个排列。
【输入格式】
The input contains several test cases. Each test case consists of two numbers, N and M(1<=N<=1000, 1<=M<=10000). You may assume that there is always a sequence satisfied the BEelzebub's demand. The input is terminated by the end of file.
【输出格式】
For each test case, you only have to output the sequence satisfied the BEelzebub's demand. When output a sequence, you should print a space between two numbers, but do not output any spaces after the last number.
【输入样例】
6 4
11 8
【输出格式】
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
【算法分析】
在使用 next_permutation() 的时候,初始序列一般是一个字典序最小的序列。
如果不是,可以用 sort() 排序,得到最小序列,然后再使用 next_permutation()。
#include <bits/stdc++.h>
using namespace std;const int maxn=100;
int a[maxn];
int n;int main() {cin>>n;for(int i=0; i<n; i++) cin>>a[i];sort(a,a+n);do {for(int i=0; i<n; i++)cout<<a[i]<<" ";cout<<endl;} while(next_permutation(a,a+n));return 0;
}/*
in:
3
1 3 2
out:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
*/
next_permutation() 用法详见官网:
https://cplusplus.com/reference/algorithm/next_permutation/
【算法代码】
#include <bits/stdc++.h>
using namespace std;const int maxn=1005;
int a[maxn];int main() {int n,m;while(cin>>n>>m) {for(int i=1; i<=n; i++) a[i]=i;int t=1;do {if(t==m) break;t++;} while(next_permutation(a+1,a+1+n));for(int i=1; i<n; i++) cout<<a[i]<<" ";cout<<a[n]<<endl;}return 0;
}/*
in:
6 4
11 8out:
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
*/
【参考文献】
https://blog.csdn.net/hnjzsyjyj/article/details/118616680
https://blog.csdn.net/hnjzsyjyj/article/details/125808608
https://cplusplus.com/reference/algorithm/next_permutation/
相关文章:
HDU 1027:Ignatius and the Princess II ← next_permutation()
【题目来源】http://acm.hdu.edu.cn/showproblem.php?pid1027【题目描述】 Now our hero finds the door to the BEelzebub feng5166. He opens the door and finds feng5166 is about to kill our pretty Princess. But now the BEelzebub has to beat our hero first. feng5…...
主题讲座:全球增材制造现状与未来(暨香港科技大学广州|智能制造学域2024博士学位全额奖学金项目)
时间:2023 年11月16日(星期四)14:30 地点:合肥工业大学 学术会议中心三楼报告厅 主讲嘉宾:陈模军 助理教授 https://facultyprofiles.hkust-gz.edu.cn/faculty-personal-page/CHEN-Mojun/mjchen 报名表直达࿱…...
hugeGraph修改PropertyKey属性类型
修改PropertyKey字段属性的类型,发现没办法保留数据的前提下修改,智能是先删除数据,然后再修改,或者备份后修改再恢复。 方法一、 修改groovy脚本中的Text为Int后重新建元数据 schema.propertyKey(“youkey”).asText().valueSing…...
vscode 访问本地或者远程docker环境
1、vscode 访问docker本地环境 直接点击左下角连接图标,弹出选项可以选择容器,只要容器在本地运行者,选择attach可以看到运行中的容器可以选择,选择其中需要选择的就行 ## 运行容器,可以-d后台运行都可以 docker run…...
人工智能与充电技术:携手共创智能充电新时代
人工智能与充电技术:携手共创智能充电新时代 摘要:本文探讨了人工智能与充电技术的结合及其在未来充电设施领域的应用。通过分析智能充电系统的技术原理、优势以及挑战,本文展望了由人工智能驱动的充电技术为未来电动交通带来的巨大变革与机…...
『自定义B站视频播放速度』
哔哩哔哩 的最高播放速度是 2.0, 但对于我们这种程序员来说,2.0 速度观看学习视频还是稍微慢了点, 🫵🏻3.0 以上才是王道🫵🏻, 下面就是具体的操作方法: ① 在浏览器…...
Java入门篇 之 继承
本篇碎碎念:最近的课程遇到瓶颈了,看的时候感觉自己会了,但是结束仔细一回顾还是一知半解,一点一点来吧,基础必须要打好(自己给自己好的心里暗示,结局一定是好的) 今日份励志文案:慢慢改变,慢慢…...
如何计算掩膜图中多个封闭图形的面积
import cv2def calMaskArea(image,idx):mask cv2.inRange(image, idx, idx)contours, hierarchy cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)for contour in contours:area cv2.contourArea(contour)print("图形的面积为", area) image是…...
【Nginx】CentOS 安装Nignx
CentOS上安装Nginx: 1. 打开终端:使用SSH或者直接在服务器上打开终端。 2. 更新系统:运行以下命令以确保您的系统软件包列表是最新的: sudo yum update3. 安装Nginx:运行以下命令以安装Nginx: sudo yum…...
idea 代码快捷键Mac版
1、查询任何东西 双击 Shift2、文件内查找 Command F 3、文件内替换 Command R4、全局查找(根据路径) Command Shift F5、在当前文件跳转到某一行的指定处 Command L6、退回 / 前进到上一个操作的地方 Command Option 方向键左Command Opt…...
【NI-DAQmx入门】多通道数据采集
1.通道扩展解释 通道扩展是扩展数据采集设备的通道以包含另一个设备的通道的过程,从而有效地创建具有更多通道的任务。当使用通道扩展时,DAQmx 自动在 DAQmx 驱动程序级别路由触发器和时钟,以便多个设备同步。为了使设备作为一个整体运行&…...
回顾 — SFA:简化快速 AlexNet(模糊分类)
模糊图像的样本 一、说明 在本文回顾了基于深度学习的模糊图像分类(SFA)。在本文中:Simplified-Fast-AlexNet (SFA)旨在对图像是否因散焦模糊、高斯模糊、雾霾模糊或运动模糊而模糊进行分类。 二、大纲 图像模糊建模简要概述简化快速 AlexNet…...
基于51单片机PCF8591数字电压表数码管显示设计( proteus仿真+程序+设计报告+讲解视频)
PCF8591数字电压表数码管显示 1.主要功能:讲解视频:2.仿真3. 程序代码4. 设计报告5. 设计资料内容清单&&下载链接资料下载链接(可点击): 基于51单片机PCF8591数字电压表数码管设计( proteus仿真程序设计报告讲…...
分发饼干(贪心算法+图解)
455. 分发饼干 - 力扣(LeetCode) 题目描述 假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。 对每个孩子 i,都有一个胃口值 g[i],这是能让孩子们满足胃口的饼干的最…...
vue项目路由使用history模式,nginx配置,刷新页面显示404
需要在配置项中添加 try_files $uri $uri/ /index.html;...
redis的redis.service配置
在CentOS中,可以使用以下步骤配置redis.service: 创建redis用户和组 在终端中执行以下命令: 复制插入 sudo useradd -r -s /bin/false redis复制插入 这将创建一个名为redis的系统用户,并禁止该用户登录系统。 安装Redis 在…...
高频SQL50题(基础版)-3
文章目录 主要内容一.SQL练习题1.1174-即时食物配送代码如下(示例): 2.550-游戏玩法分析代码如下(示例): 3.2356-每位教师所教授的科目种类的数量代码如下(示例): 4.1141-查询近30天活跃用户数代码如下&…...
OpenMMlab导出yolov3模型并用onnxruntime和tensorrt推理
导出onnx文件 直接使用脚本 import torch from mmdet.apis import init_detector, inference_detectorconfig_file ./configs/yolo/yolov3_mobilenetv2_8xb24-ms-416-300e_coco.py checkpoint_file yolov3_mobilenetv2_mstrain-416_300e_coco_20210718_010823-f68a07b3.pth…...
单链表的插入删除
#include <iostream>#include <stdio.h> #include <stdlib.h>using namespace std;//带头指针的单链表typedef struct LNode{int data;struct LNode *next;}LNode, *LinkList;bool InitList(LinkList &L){L (LNode *) malloc(sizeof(LNode));if(L NUL…...
github使用手册
核心代码 配置用户名/邮箱 best practice git init #在本地初始化一个仓库 git add . #将当前目录所有的文件加入(注意这里是加入)到缓存区 git commit -m "xxx" #将当前缓存区里的内容提交到本地仓库 git remote add <remote_rep_name&g…...
利用最小二乘法找圆心和半径
#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …...
XCTF-web-easyupload
试了试php,php7,pht,phtml等,都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接,得到flag...
51c自动驾驶~合集58
我自己的原文哦~ https://blog.51cto.com/whaosoft/13967107 #CCA-Attention 全局池化局部保留,CCA-Attention为LLM长文本建模带来突破性进展 琶洲实验室、华南理工大学联合推出关键上下文感知注意力机制(CCA-Attention),…...
JavaScript 中的 ES|QL:利用 Apache Arrow 工具
作者:来自 Elastic Jeffrey Rengifo 学习如何将 ES|QL 与 JavaScript 的 Apache Arrow 客户端工具一起使用。 想获得 Elastic 认证吗?了解下一期 Elasticsearch Engineer 培训的时间吧! Elasticsearch 拥有众多新功能,助你为自己…...
定时器任务——若依源码分析
分析util包下面的工具类schedule utils: ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类,封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz,先构建任务的 JobD…...
新能源汽车智慧充电桩管理方案:新能源充电桩散热问题及消防安全监管方案
随着新能源汽车的快速普及,充电桩作为核心配套设施,其安全性与可靠性备受关注。然而,在高温、高负荷运行环境下,充电桩的散热问题与消防安全隐患日益凸显,成为制约行业发展的关键瓶颈。 如何通过智慧化管理手段优化散…...
MFC 抛体运动模拟:常见问题解决与界面美化
在 MFC 中开发抛体运动模拟程序时,我们常遇到 轨迹残留、无效刷新、视觉单调、物理逻辑瑕疵 等问题。本文将针对这些痛点,详细解析原因并提供解决方案,同时兼顾界面美化,让模拟效果更专业、更高效。 问题一:历史轨迹与小球残影残留 现象 小球运动后,历史位置的 “残影”…...
08. C#入门系列【类的基本概念】:开启编程世界的奇妙冒险
C#入门系列【类的基本概念】:开启编程世界的奇妙冒险 嘿,各位编程小白探险家!欢迎来到 C# 的奇幻大陆!今天咱们要深入探索这片大陆上至关重要的 “建筑”—— 类!别害怕,跟着我,保准让你轻松搞…...
windows系统MySQL安装文档
概览:本文讨论了MySQL的安装、使用过程中涉及的解压、配置、初始化、注册服务、启动、修改密码、登录、退出以及卸载等相关内容,为学习者提供全面的操作指导。关键要点包括: 解压 :下载完成后解压压缩包,得到MySQL 8.…...
pycharm 设置环境出错
pycharm 设置环境出错 pycharm 新建项目,设置虚拟环境,出错 pycharm 出错 Cannot open Local Failed to start [powershell.exe, -NoExit, -ExecutionPolicy, Bypass, -File, C:\Program Files\JetBrains\PyCharm 2024.1.3\plugins\terminal\shell-int…...
