A - Special Permutation(构造)Codeforces Round #686 (Div. 3)
原题链接; http://codeforces.com/contest/1454/problem/A

测试样例
input
2
2
5
output
2 1
2 1 5 3 4
题意: 给你一个整数 n n n,构造一个 1 1 1~ n n n的排列,使得元素对应的位置不等于其值。
解题思路: 算是一道构造水题,有很多的方法去构造,最简单的方法就是将 1 1 1~ n n n整体循环一位构造。
AC代码
/*
*blog:https://blog.csdn.net/hzf0701
*邮箱:unique_powerhouse@qq.com
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*/
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
using namespace std;
typedef long long ll;
const int maxn=1e5;//数组所开最大值
const int mod=1e9+7;//模
const int inf=0x3f3f3f3f;//无穷大
int t,n;
void solve(){
    cout<<n<<" ";
    rep(i,1,n-1){
        cout<<i<<" ";
    }
    cout<<endl;
}
int main(){
    while(cin>>t){
        while(t--){
            cin>>n;
            solve();
        }
    }
    return 0;
}

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号