简答题 偏难
#23339

#include <cstdio> using namespace std; const int N = 110; bool isUse[N]; int n,…

#include <cstdio>

using namespace std;

const int N = 110;

bool isUse[N];

int n, t;

int a[N], b[N];

bool isSmall() {

for (int i = 1; i <= n; ++i)

if (a[i] != b[i]) return a[i] < b[i];

return false;

}

bool getPermutation(int pos) {

if (pos > n) {

return isSmall();

}

for (int i = 1; i <= n; ++i) {

if (!isUse[i]) {

b[pos] = i; isUse[i] = true;

if (getPermutation(pos + 1)) {

return true;

}

isUse[i] = false;

}

}

return false;

}

void getNext() {

for (int i = 1; i <= n; ++i) {

isUse[i] = false;

}

getPermutation(1);

for (int i = 1; i <= n; ++i) {

a[i] = b[i];

}

}

int main() {

scanf("%d%d", &n, &t);

for (int i = 1; i <= n; ++i) {

scanf("%d", &a[i]);

}

for (int i = 1; i <= t; ++i) {

getNext();

}

for (int i = 1; i <= n; ++i) {

printf("%d", a[i]);

if (i == n) putchar('\n'); else putchar(' ');

}

return 0;

}

输入 1:6 10 1 6 4 5 3 2

输出 1:_________(3 分)

输入 2:6 200 1 5 3 4 2 6

输出 2:_________(5 分)

未登录也能判分,登录后才会记录
答案与解析
正确答案:<p>输出 1:2 1 3 5 6 4 (3 分)</p><p> 输出 2:3 2 5 6 1 4 (5 分)</p>
这道题暂未补解析。