2431: 【普及-】【P1088】火星人

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:6 解决:4

题目描述

人类终于登上了火星的土地并且见到了神秘的火星人。人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法。这种交流方法是这样的,首先,火星人把一个非常大的数字告诉人类科学家,科学家破解这个数字的含义后,再把一个很小的数字加到这个大数上面,把结果告诉火星人,作为人类的回答。

火星人用一种非常简单的方式来表示数字――掰手指。火星人只有一只手,但这只手上有成千上万的手指,这些手指排成一列,分别编号为 lns="http://www.w3.org/1998/Math/MathML">1,2,3,。火星人的任意两根手指都能随意交换位置,他们就是通过这方法计数的。

一个火星人用一个人类的手演示了如何用手指计数。如果把五根手指――拇指、食指、中指、无名指和小指分别编号为 lns="http://www.w3.org/1998/Math/MathML">1,2,3,4 和 lns="http://www.w3.org/1998/Math/MathML">5,当它们按正常顺序排列时,形成了 lns="http://www.w3.org/1998/Math/MathML">5 位数 lns="http://www.w3.org/1998/Math/MathML">12345,当你交换无名指和小指的位置时,会形成 lns="http://www.w3.org/1998/Math/MathML">5 位数 lns="http://www.w3.org/1998/Math/MathML">12354,当你把五个手指的顺序完全颠倒时,会形成 lns="http://www.w3.org/1998/Math/MathML">54321,在所有能够形成的 lns="http://www.w3.org/1998/Math/MathML">120 个 lns="http://www.w3.org/1998/Math/MathML">5 位数中,lns="http://www.w3.org/1998/Math/MathML">12345 最小,它表示 lns="http://www.w3.org/1998/Math/MathML">1lns="http://www.w3.org/1998/Math/MathML">12354 第二小,它表示 lns="http://www.w3.org/1998/Math/MathML">2lns="http://www.w3.org/1998/Math/MathML">54321 最大,它表示 lns="http://www.w3.org/1998/Math/MathML">120。下表展示了只有 lns="http://www.w3.org/1998/Math/MathML">3 根手指时能够形成的 lns="http://www.w3.org/1998/Math/MathML">6 个 lns="http://www.w3.org/1998/Math/MathML">3 位数和它们代表的数字:

三进制数 代表的数字
lns="http://www.w3.org/1998/Math/MathML">123 lns="http://www.w3.org/1998/Math/MathML">1
lns="http://www.w3.org/1998/Math/MathML">132 lns="http://www.w3.org/1998/Math/MathML">2
lns="http://www.w3.org/1998/Math/MathML">213 lns="http://www.w3.org/1998/Math/MathML">3
lns="http://www.w3.org/1998/Math/MathML">231 lns="http://www.w3.org/1998/Math/MathML">4
lns="http://www.w3.org/1998/Math/MathML">312 lns="http://www.w3.org/1998/Math/MathML">5
lns="http://www.w3.org/1998/Math/MathML">321 lns="http://www.w3.org/1998/Math/MathML">6

现在你有幸成为了第一个和火星人交流的地球人。一个火星人会让你看他的手指,科学家会告诉你要加上去的很小的数。你的任务是,把火星人用手指表示的数与科学家告诉你的数相加,并根据相加的结果改变火星人手指的排列顺序。输入数据保证这个结果不会超出火星人手指能表示的范围。

输入

共三行。
第一行一个正整数 lns="http://www.w3.org/1998/Math/MathML">,表示火星人手指的数目(lns="http://www.w3.org/1998/Math/MathML">110000)。
第二行是一个正整数 lns="http://www.w3.org/1998/Math/MathML">,表示要加上去的小整数(lns="http://www.w3.org/1998/Math/MathML">1100)。
下一行是 lns="http://www.w3.org/1998/Math/MathML">1 到 lns="http://www.w3.org/1998/Math/MathML"> 这 lns="http://www.w3.org/1998/Math/MathML"> 个整数的一个排列,用空格隔开,表示火星人手指的排列顺序。

输出

 个整数,表示改变后的火星人手指的排列顺序。每两个相邻的数中间用一个空格分开,不能有多余的空格。

样例输入 复制

5
3
1 2 3 4 5

样例输出 复制

1 2 4 5 3

提示

对于 lns="http://www.w3.org/1998/Math/MathML">30% 的数据,lns="http://www.w3.org/1998/Math/MathML">15

对于 lns="http://www.w3.org/1998/Math/MathML">60% 的数据,lns="http://www.w3.org/1998/Math/MathML">50

对于 lns="http://www.w3.org/1998/Math/MathML">100% 的数据,lns="http://www.w3.org/1998/Math/MathML">10000

noip2004 普及组第 4 题

#include<bits/stdc++.h>
using namespace std;
int a[10010],n,m;
int main(){
    cin>>n>>m;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    for(;m--;)
        next_permutation(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        cout<<a[i]<<' ';
	return 0;
}