[蓝桥杯2019初赛]修改数组-并查集
生活随笔
收集整理的這篇文章主要介紹了
[蓝桥杯2019初赛]修改数组-并查集
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼如下:
#include <iostream> using namespace std; const int N = 1000010; int a[N];int find(int x) {if (a[x] != x)a[x] = find(a[x]);return a[x]; }int main() {int n;cin >> n;for (int i = 1; i <= N; i++)a[i] = i;for (int i = 1; i <= n; i++) {int x;cin >> x;x = find(x);cout << a[x] << " ";a[x] = x + 1;}return 0; }總結
以上是生活随笔為你收集整理的[蓝桥杯2019初赛]修改数组-并查集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [蓝桥杯2019初赛]完全二叉树的权值-
- 下一篇: [蓝桥杯2019初赛]年号字串-数论+模