pat1067 Sort with Swap(0,*)
来源:互联网 发布:淘宝达人互动视频教程 编辑:程序博客网 时间:2024/06/06 08:57
#include<cstdio>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<string>#include<cstring>#include<cmath>#include<map>#include<stack>#define N 100005#define ll long longusing namespace std;vector<pair<int,int> >v;int a[N],pos[N],vis[N];int main(){int n,i,j,ans;while(scanf("%d",&n)!=EOF){ans = 0;for(i = 0;i<n;i++){scanf("%d",&a[i]);pos[a[i]] = i;}for(i = 0;i<n;i++){if(!vis[i]&&a[i]!=i){vis[i] = 1;j = pos[i];while(j!=i){vis[j] = 1;j = pos[j];ans++;}ans+=2;}}if(a[0]!=0)ans-=2;printf("%d\n",ans);} return 0;}
0 0
- pat1067 Sort with Swap(0,*)
- PAT1067 Sort with Swap(0,*)
- 1067. Sort with Swap(0,*)
- 1067. Sort with Swap(0,*)
- 1067 Sort with Swap(0,*)
- 1067. Sort with Swap(0,*)
- 1067.Sort with Swap(0,*)
- 1067. Sort with Swap(0,*)
- 1067. Sort with Swap(0,*)
- Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*)
- 1067. Sort with Swap(0,*)
- Sort with Swap(0,*)(25)
- Sort with Swap(0, i)
- PAT_1067. Sort with Swap(0,*)
- Sort with Swap(0, i)
- 【PAT】1067. Sort with Swap(0,*)
- 1067. Sort with Swap(0,*) (25)
- js实现不缓存
- oracle 日志
- Linux I2C驱动完全分析(一)
- J-Linkage多模型分类算法简介
- Android程序的隐藏与退出
- pat1067 Sort with Swap(0,*)
- 微信开发学习日记(一):快速阅读5本书,掌握整体背景
- iOS问题
- hdu 1010 Tempter of the Bone
- bash脚本配合ant多渠道打包
- 【BZOJ3892】【Usaco2014 Dec】Marathon (Silver and Bronze) 暴力动规
- 循环链表 猴子选大王
- Tomcat打包时多项目共享jar和精确指定jar版本
- iOS开发——创建你自己的Framework