博客
关于我
C. Crazy Diamond(思维+构造)
阅读量:238 次
发布时间:2019-03-01

本文共 797 字,大约阅读时间需要 2 分钟。


思路:发现1和n比较特殊,通过1和n作为中转站每次把数字在这里转。

<=n/2的要在左边的数字先和n换,再换到1. <=n/2的在右边的先和1换,再和n换,再和i换。

>=n/2+1同理

#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug(a) cout<<#a<<"="<
<
P;inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}return x*f;}LL a[maxn],pos[maxn];vector

ans;void op(LL x,LL y){ ans.push_back({x,y}); swap(pos[a[x]],pos[a[y]]); swap(a[x],a[y]);}int main(void){ cin.tie(0);std::ios::sync_with_stdio(false); LL n;cin>>n; for(LL i=1;i<=n;i++){ cin>>a[i]; pos[a[i]]=i; } for(LL i=2;i<=n/2;i++){ if(pos[i]<=n/2){ op(pos[i],n); op(n,i); } else{ op(pos[i],1); op(1,n); op(n,i); } } for(LL i=n/2+1;i

 

转载地址:http://cict.baihongyu.com/

你可能感兴趣的文章
mysql sum 没返回,如果没有找到任何值,我如何在MySQL中获得SUM函数以返回'0'?
查看>>
mysql Timestamp时间隔了8小时
查看>>
Mysql tinyint(1)与tinyint(4)的区别
查看>>
mysql union orderby 无效
查看>>
mysql v$session_Oracle 进程查看v$session
查看>>
mysql where中如何判断不为空
查看>>
MySQL Workbench 使用手册:从入门到精通
查看>>
mysql workbench6.3.5_MySQL Workbench
查看>>
MySQL Workbench安装教程以及菜单汉化
查看>>
MySQL Xtrabackup 安装、备份、恢复
查看>>
mysql [Err] 1436 - Thread stack overrun: 129464 bytes used of a 286720 byte stack, and 160000 bytes
查看>>
MySQL _ MySQL常用操作
查看>>
MySQL – 导出数据成csv
查看>>
MySQL —— 在CentOS9下安装MySQL
查看>>
MySQL —— 视图
查看>>
mysql 不区分大小写
查看>>
mysql 两列互转
查看>>
MySQL 中开启二进制日志(Binlog)
查看>>
MySQL 中文问题
查看>>
MySQL 中日志的面试题总结
查看>>