[Codeforces 519B] A and B and Compilation Errors
Posted evenbao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Codeforces 519B] A and B and Compilation Errors相关的知识,希望对你有一定的参考价值。
[题目链接]
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 ",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 ",ans); return 0; }
以上是关于[Codeforces 519B] A and B and Compilation Errors的主要内容,如果未能解决你的问题,请参考以下文章
codeforces 416B. Appleman and Tree 树形dp
codeforces 623A. Graph and String 构造
Codeforces 519E A and B and Lecture Rooms [倍增法LCA]
A and B CodeForces - 1278B math