Codeforces Round #686 (Div. 3)_A. Special Permutation
程序员文章站
2022-03-14 19:53:08
A. Special Permutation题目链接在此!题面:ExampleinputCopy225outputCopy2 12 1 5 3 4题意分析:1~n的序列,要求a[i]!=i即可。思路:倒着放,如果n是奇数就把中间那个a[n/2+1]与首位调换顺序。达到目的。代码块:#include #include #include #include ...
A. Special Permutation
题面:
Example
inputCopy
2
2
5
outputCopy
2 1
2 1 5 3 4
题意分析:
1~n的序列,要求a[i]!=i即可。
思路:倒着放,如果n是奇数就把中间那个a[n/2+1]与首位调换顺序。达到目的。
代码块:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
int n;
int a[1001];
cin>>n;
if(n%2==0){
for(int i=1;i<=n;i++){
a[i]=i;
}
cout<<a[n];
for(int i=n-1;i>=1;i--){
cout<<" "<<a[i];
}
cout<<endl;
}
else{
for(int i=1;i<=n;i++){
a[i]=i;
}
int temp;
temp=a[1];
a[1]=a[n/2+1];
a[n/2+1]=temp;
cout<<a[n];
for(int i=n-1;i>=1;i--){
cout<<" "<<a[i];
}
cout<<endl;
}
}
}
感觉写繁琐了,不过无所谓啦。
本文地址:https://blog.csdn.net/weixin_45849398/article/details/110108805
推荐阅读
-
Codeforces Round #686 (Div. 3) A. Special Permutation
-
A. Add Odd or Subtract Even(思维题) Codeforces Round #624 (Div. 3)
-
Codeforces Round #686 (Div. 3) F. Array Partition
-
A. Circle of Students(遍历匹配)Codeforces Round #579 (Div. 3)
-
Codeforces Round #656 (Div. 3) A. Three Pairwise Maximums
-
Codeforces Round #686 (Div. 3)_A. Special Permutation
-
Codeforces Round #144 (Div. 2)-A. Perfect Permutation_html/css_WEB-ITnose
-
Codeforces Round #144 (Div. 2)-A. Perfect Permutation_html/css_WEB-ITnose
-
Codeforces Round #686 (Div. 3) A. Special Permutation
-
Codeforces Round #656 (Div. 3) A. Three Pairwise Maximums