1067. Sort with Swap(0,*) (25)
来源:互联网 发布:淘宝服装店铺简介范文 编辑:程序博客网 时间:2024/06/16 06:55
#include<cstdio>#include<algorithm>using namespace std;const int maxn = 100010;int pos[maxn];int main(){ int n,ans=0; scanf("%d",&n); int left = n-1,num; for(int i=0; i<n; i++) { scanf("%d",&num); pos[num] = i; if(num == i && num!=0) left--; } int k = 1; while(left>0) { if(pos[0]==0) { while(k < n) { if(pos[k] != k) { swap(pos[0],pos[k]); ans++; break; } k++; } } while(pos[0] != 0) { swap(pos[0],pos[pos[0]]); ans++; left--; } } printf("%d\n",ans); return 0;}
0 0
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- pat 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- PAT 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 【PAT】1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 1067. Sort with Swap(0,*) (25)
- 2017UESTC 数据结构专题题解
- Android Studio 结合 ButterKnife Zelezny 高效使用 Butterknife(黄油刀)
- JavaScript语言基础---(十五)应用编程练习--制作二级下拉菜单
- Qt中foreach的用法
- c++之指针一
- 1067. Sort with Swap(0,*) (25)
- 【设计模式】简单工厂模式
- [leetcode:python]35.Search Insert Position
- android实现文件排序
- Matlab编程小技巧
- LeetCode 34.Search for a Range & 36.Valid Sudoku
- CCNU校赛2017
- 1069. The Black Hole of Numbers (20)
- ImportError: No module named _caffe