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…...
CSS动画+超级千问:打造有呼吸感的语音合成反馈系统(实战教程)
CSS动画超级千问:打造有呼吸感的语音合成反馈系统(实战教程) 1. 项目介绍与核心价值 1.1 传统TTS工具的痛点 大多数语音合成工具的操作体验是这样的:面对一堆参数滑块,反复调整"语速"、"音高"、…...
YOLO12入门必看:从上传图片到JSON结果输出完整操作流程
YOLO12入门必看:从上传图片到JSON结果输出完整操作流程 1. 引言:为什么你需要了解YOLO12? 如果你正在寻找一个既快又准的目标检测工具,那么YOLO12的出现,可能就是你一直在等的那个答案。 想象一下这样的场景&#x…...
抖音音乐高效解决方案:douyin-downloader批量下载与智能管理指南
抖音音乐高效解决方案:douyin-downloader批量下载与智能管理指南 【免费下载链接】douyin-downloader A practical Douyin downloader for both single-item and profile batch downloads, with progress display, retries, SQLite deduplication, and browser fall…...
突破内容壁垒:5大核心优势解锁知识自由
突破内容壁垒:5大核心优势解锁知识自由 【免费下载链接】bypass-paywalls-chrome-clean 项目地址: https://gitcode.com/GitHub_Trending/by/bypass-paywalls-chrome-clean 在信息爆炸的数字时代,付费墙已成为获取优质内容的主要障碍。无论是学术…...
springboot+vue基于web的在线学习资源推荐的设计与实现
目录功能模块分析推荐系统功能交互功能设计后台管理功能技术实现要点项目技术支持源码获取详细视频演示 :文章底部获取博主联系方式!同行可合作功能模块分析 用户管理模块 用户注册与登录:支持邮箱/手机号注册,提供密码找回功能…...
Thorium浏览器:重新定义Chromium性能与隐私体验的开源解决方案
Thorium浏览器:重新定义Chromium性能与隐私体验的开源解决方案 【免费下载链接】thorium Chromium fork named after radioactive element No. 90. Windows and MacOS/Raspi/Android/Special builds are in different repositories, links are towards the top of t…...
白鲸开源架构师获邀成为 ASF Member
在技术领域,我们常常被那些闪耀的、可见的成果所吸引。今天,这个焦点无疑是大语言模型技术。它们的流畅对话、惊人的创造力,让我们得以一窥未来的轮廓。然而,作为在企业一线构建、部署和维护复杂系统的实践者,我们深知…...
Hunyuan-MT-7B-WEBUI新手必看:5分钟搞定部署,开启多语言翻译之旅
Hunyuan-MT-7B-WEBUI新手必看:5分钟搞定部署,开启多语言翻译之旅 1. 为什么选择Hunyuan-MT-7B-WEBUI 在全球化交流日益频繁的今天,语言障碍成为许多个人和团队面临的实际问题。Hunyuan-MT-7B-WEBUI作为腾讯混元开源系列中的翻译专用模型&am…...
从裸机到RTOS:IMX6ULL启动流程与FreeRTOS源码实战解析
1. IMX6ULL裸机启动机制详解 第一次拿到IMX6ULL开发板时,很多人会疑惑:为什么我的程序烧录进去没反应?这得从芯片的启动机制说起。IMX6ULL上电后最先执行的并不是我们写的代码,而是芯片内部ROM中的固化程序。这个ROM代码就像个尽职…...
Kimi-K2-W8A8量化版:推理精度反超官方!
Kimi-K2-W8A8量化版:推理精度反超官方! 【免费下载链接】KIMI-k2-Thinking-W8A8-QuaRot 项目地址: https://ai.gitcode.com/Eco-Tech/KIMI-k2-Thinking-W8A8-QuaRot 导语:国内大模型量化技术再获突破——Kimi-K2-Thinking模型的W8A8量…...
