博客
关于我
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基础知识:创建MySQL数据库和表
查看>>
MySQL基础系列—SQL分类之一
查看>>
MySQL处理千万级数据分页查询的优化方案
查看>>
mysql备份
查看>>
mysql备份与恢复
查看>>
mysql备份工具xtrabackup
查看>>
mysql备份恢复出错_尝试备份/恢复mysql数据库时出错
查看>>
mysql复制内容到一张新表
查看>>
mysql复制表结构和数据
查看>>
mysql复杂查询,优质题目
查看>>
MySQL外键约束
查看>>
MySQL多表关联on和where速度对比实测谁更快
查看>>
MySQL多表左右连接查询
查看>>
mysql大批量删除(修改)The total number of locks exceeds the lock table size 错误的解决办法
查看>>
mysql如何做到存在就更新不存就插入_MySQL 索引及优化实战(二)
查看>>
mysql如何删除数据表,被关联的数据表如何删除呢
查看>>
MySQL如何实现ACID ?
查看>>
mysql如何记录数据库响应时间
查看>>
MySQL子查询
查看>>
Mysql字段、索引操作
查看>>