ATABC C求调
  • 板块灌水区
  • 楼主Little_x_starTYJ
  • 当前回复11
  • 已保存回复11
  • 发布时间2024/4/20 21:39
  • 上次更新2024/4/21 01:02:32
查看原帖
ATABC C求调
902351
Little_x_starTYJ楼主2024/4/20 21:39

WA ×\times 10

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200010];
int c[200010], ans;
struct node {
	int x, y;
} d[200010];
int main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		c[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (i != a[i]) {
			swap(a[c[i]], a[i]);
			d[++ans].x = i, d[ans].y = c[i];
			c[a[i]] = c[i];
			c[i] = i;
			
		}
	}
	cout << ans << endl;
	for (int i = 1; i <= ans; i++) {
		cout << d[i].x << ' ' << d[i].y << endl;
	}
	return 0;
}
2024/4/20 21:39
加载中...