【洛谷-P1177】解题报告(排序)

原始题目

P1177 【模板】快速排序

题目大意

快排模板不解释

解题思路

快排模板不解释

解题代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn = 1e5 + 5;

#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define fi first
#define se second
#define pb push_back
#define np next_permutation
#define mp make_pair

int a[maxn], n, vis[maxn];
int main()
{
ios::sync_with_stdio(false);
while (cin >> n) {
memset(vis, 0, sizeof(vis));
int cnt = 0;
rep(i, 0, n)
{
int temp;
cin >> temp;
if (!vis[temp]) {
a[cnt++] = temp;
vis[temp] = 1;
}
}
sort(a, a + cnt);
cout << cnt << "\n";
cout << a[0];
rep(i, 1, cnt)
{
cout << " " << a[i];
}
cout << "\n";
}
}

收获与反思