ACGO欢乐赛#42题解
2025-03-10 20:49:32
发布于:浙江
15阅读
0回复
0点赞
Solution
发现此题为红题,只需要枚举 的全排列即可,更高效的算法可以让 deepseek 帮你解决。
Code
#include <bits/stdc++.h>
#include <cstdio>
#define int long long
#define ull unsigned long long
#define mod 998244353
#define MOD 1000000007
using namespace std;
const int N = 2e6 + 5,maxn = 3e3 + 5;
int a [N];
inline int read ()
{
int x = 0;
bool f = 1;
char c = getchar ();
while (c < '0' || c > '9') f = (c == '-' ? !f : f),c = getchar ();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48),c = getchar ();
return (f ? x : -x);
}
inline void write (int x)
{
if (x < 0) putchar ('-'),x = -x;
if (x > 9) write (x / 10);
putchar (x % 10 + '0');
return ;
}
signed main ()
{
int n;
cin >> n;
int m;
cin >> m;
for (int i = 1;i <= n;i ++) a [i] = i;
if (m == 1)
{
for (int i = 1;i <= n;i ++) cout << a [i] << ' ';
return 0;
}
while (next_permutation (a + 1,a + n + 1))
{
m --;
if (m == 1)
{
for (int i = 1;i <= n;i ++) cout << a [i] << ' ';
}
}
return 0;
}
这里空空如也
有帮助,赞一个