CodeForces 519B A and B and Compilation Errors【模拟】

时间:2023-03-09 23:39:14
CodeForces 519B A and B and Compilation Errors【模拟】

题目意思还是蛮简单的,看 输入数据输出数据还是比较明显的

我用排序来写还是可以AC的

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ;
const int INF = 0x3f3f3f3f ;
const int offset = ; int a[], b[], c[];
int n; int main () {
std::ios::sync_with_stdio (false);
int i, j, t, k, u, v, numCase = ; cin >> n;
for (i = ; i < n; ++i) cin >> a[i];
for (i = ; i < n - ; ++i) cin >> b[i];
for (i = ; i < n - ; ++i) cin >> c[i]; sort (a, a + n);
sort (b, b + n - );
sort (c, c + n - ); for (i = ; i < n - ; ++i) {
if (a[i] != b[i]) {
cout << a[i] << endl;
break;
}
}
if (i == n - ) {
cout << a[n - ] << endl;
} for (i = ; i < n - ; ++i) {
if (b[i] != c[i]) {
cout << b[i] << endl;
break;
}
}
if (i == n - ) {
cout << b[n - ] << endl;
} return ;
}

Sort Solution

不过看了官方题解,还有更快的方法。

因为这题的数据规模在 n - 10^5  ai - 10 ^ 9 ,如果对所有的数字作一个累加的话还是可以存放在 long long 类型的变量中

Source Code:

/****************************************
** Solution by Bekzhan Kassenov **
****************************************/ #include <bits/stdc++.h> using namespace std; #define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end() typedef long long ll;
typedef unsigned long long ull;
typedef long double ld; const double EPS = 1e-;
const double PI = acos(-1.0);
const int MOD = * * + ;
const int INF = * * ; template <typename T>
inline T sqr(T n) {
return n * n;
} int n, x;
long long a, b, c; int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
#endif scanf("%d", &n); for (int i = ; i < n; i++) {
scanf("%d", &x);
a += x;
} for (int i = ; i < n - ; i++) {
scanf("%d", &x);
b += x;
} for (int i = ; i < n - ; i++) {
scanf("%d", &x);
c += x;
} printf("%I64d\n%I64d\n", a - b, b - c); return ;
}