样例对,全WA,0分
查看原帖
样例对,全WA,0分
552387
DeltaCR楼主2023/5/1 13:28

以防万一,我还按字典序排了个序。样例过了,换顺序也没问题

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int N = 1e3 + 5;
struct Child
{
    string name;
    int c, m, e;
}  children[N];
int n;

inline bool Check(const Child &a, const Child &b)
{
    int suma = a.c + a.m + a.e;
    int sumb = b.c + b.m + b.e;
    return (abs(a.c - b.c) <= 5) && (abs(a.m - b.m) <= 5) && (abs(a.e - b.e) <= 5) && (abs(suma - sumb) <= 10);
}

inline bool Cmp(const Child &a, const Child &b) { return a.name <= b.name; }

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> children[i].name >> children[i].c >> children[i].m >> children[i].e;
    sort(children, children + n, Cmp);
    for (int i = 1; i < n; i++)
        for (int j = 0; j < i; j++)
        {
            Child a = children[j];
            Child b = children[i];
            if (Check(a, b)) cout << a.name << " " << b.name << endl;
        }
    return 0;
}
2023/5/1 13:28
加载中...