A. Permutation Forgery(非常水题)Codeforces Round #668 (Div. 2)
原题链接:https://codeforces.com/contest/1405/problems
测试样例
input
3
2
1 2
6
2 1 6 5 4 3
5
2 4 3 1 5
output
2 1
1 2 5 6 3 4
3 1 5 2 4
Note
In the first test case, F§=sort([1+2])=[3].
And F(p′)=sort([2+1])=[3].
In the second test case, F§=sort([2+1,1+6,6+5,5+4,4+3])=sort([3,7,11,9,7])=[3,7,7,9,11].
And F(p′)=sort([1+2,2+5,5+6,6+3,3+4])=sort([3,7,11,9,7])=[3,7,7,9,11].
In the third test case, F§=sort([2+4,4+3,3+1,1+5])=sort([6,7,4,6])=[4,6,6,7].
And F(p′)=sort([3+1,1+5,5+2,2+4])=sort([4,6,7,6])=[4,6,6,7].
题意: 给你一个1~n的排列数组,请你输出一个1 ~n的排列数组和给定的顺序不同,使得F§相同。
解题思路: 一道思维水题,既然是这样,我们想到的就是不能更换组合的顺序,那么我们将排列数组反过来构建就可以了,这样组合是不变的。
AC代码
/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//
int t,n,a[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n;
rep(i,0,n-1){
cin>>a[i];
}
per(i,n-1,0){
cout<<a[i]<<" ";
}
cout<<endl;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)