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;
}
posted @   unique_pursuit  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示