首页 > 学院 > 开发设计 > 正文

1067. Sort with Swap(0,*) (25)

2019-11-08 03:07:50
字体:
来源:转载
供稿:网友

除了位置0,其他位置一旦对应就从存储容器中删除,直到存储容器中只剩下0, 要考虑rr[0]==0的特殊情况

#include<iostream>#include<map>#PRagma warning(disable:4996)using namespace std;int main(){ int N; int cnt = 0; int tt = 0; cin >> N; map<int, int> rr;//数据,位置(存储容器) for (int t = 0;t < N;t++) { int temp; scanf("%d", &temp); if (temp == 0 || temp != t) rr[temp] = t; } while (rr.size() != 1) { if (rr[0] == 0) { auto it = rr.begin(); it++; rr[0] = (*it).second; it->second = 0; cnt++; } int tem = rr[0]; rr[0] = rr[tem]; rr.erase(tem); cnt++; } cout << cnt << endl;}
上一篇:linux常用命令

下一篇:正则表达式匹配

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表