[题目链接]
https://codeforces.com/problemset/problem/519/B
[算法]
将三个序列分别排序,然后对比元素即可
时间复杂度 : O(NlogN)
[代码]
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int n,ans; int a[MAXN],b[MAXN],c[MAXN]; template <typename T> inline void read(T &x) { T f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= f; } int main() { int n; read(n); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n - 1; i++) read(b[i]); for (int i = 1; i <= n - 2; i++) read(c[i]); sort(a + 1,a + n + 1); sort(b + 1,b + (n - 1) + 1); sort(c + 1,c + (n - 2) + 1); int ans = -1; for (int i = 1; i <= n - 1; i++) { if (a[i] == b[i]) continue; ans = a[i]; break; } if (ans == -1) ans = a[n]; printf("%d\n",ans); ans = -1; for (int i = 1; i <= n - 2; i++) { if (b[i] == c[i]) continue; ans = b[i]; break; } if (ans == -1) ans = b[n - 1]; printf("%d\n",ans); return 0; }