当前位置:网站首页>Luogu p1088 Martians

Luogu p1088 Martians

2022-06-13 05:00:00 Clown clown clown

Topic link : Martian

Knowledge point
next_permutation Use . notes :C There is no such function in the language .
next_permutation Is to find the total permutation of a sequence , A sequence slightly larger than the current sequence dictionary order ( only ).

for example 1 2 3 4 5 Of next_permutation yes 1 2 3 5 4, Once again next_permutation yes 1 2 5 3 4.

If it keeps going next_permutation Words , Until it becomes 5 4 3 2 1( The maximum order of the current sequence dictionary )

The meaning of this question is that a sequence is sorted according to the size of the dictionary order in the whole arrangement , mapping 1,2,3,….

So with next_permutation Just right .

AC Code :

#include <iostream>
#include <algorithm>
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] << ' ';
}
原网站

版权声明
本文为[Clown clown clown]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280516403966.html