栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

洛谷P1088火星人

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

洛谷P1088火星人

题目链接:火星人

知识点
next_permutation的使用。注:C语言里面没有这个函数。
next_permutation是求一个序列的全排列中,比当前序列字典序稍大的一个序列(唯一)。

例如 1 2 3 4 5 的next_permutation是1 2 3 5 4,再来一次next_permutation是1 2 5 3 4.

假若一直进行next_permutation的话,会直到变成 5 4 3 2 1(当前序列字典序最大的情况)

本题题意就是一个序列在全排列中按照字典序的大小来排序,映射成1,2,3,…。

因此用next_permutation正好。

AC代码:

#include 
#include 
using namespace std;

const int N = 10010;
int n, m;
int a[N];


int main()
{
	cin >> n >> m;
	string s,t;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < m; i++) next_permutation(a, a + n);
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665535.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号