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-7      ;
const int N = 210            ;
const int M = 1100011*2      ;
const ll P = 10000000097ll   ;
const int MAXN = 10900000    ;
const int INF = 0x3f3f3f3f   ;
const int offset = 100       ;

int a[120000], b[120000], c[120000];
int n;

int main () {
    std::ios::sync_with_stdio (false);
    int i, j, t, k, u, v, numCase = 0;

    cin >> n;
    for (i = 0; i < n; ++i) cin >> a[i];
    for (i = 0; i < n - 1; ++i) cin >> b[i];
    for (i = 0; i < n - 2; ++i) cin >> c[i];

    sort (a, a + n);
    sort (b, b + n - 1);
    sort (c, c + n - 2);

    for (i = 0; i < n - 1; ++i) {
        if (a[i] != b[i]) {
            cout << a[i] << endl;
            break;
        }
    }
    if (i == n - 1) {
        cout << a[n - 1] << endl;
    }

    for (i = 0; i < n - 2; ++i) {
        if (b[i] != c[i]) {
            cout << b[i] << endl;
            break;
        }
    }
    if (i == n - 2) {
        cout << b[n - 2] << endl;
    }

    return 0;
}
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-9;
const double PI = acos(-1.0);
const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 2000 * 1000 * 1000;

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 = 0; i < n; i++) {
        scanf("%d", &x);
        a += x;
    }

    for (int i = 0; i < n - 1; i++) {
        scanf("%d", &x);
        b += x;
    }

    for (int i = 0; i < n - 2; i++) {
        scanf("%d", &x);
        c += x;
    }

    printf("%I64d
%I64d
", a - b, b - c);

    return 0;
}
原文地址:https://www.cnblogs.com/wushuaiyi/p/4398494.html