1 条题解

  • 0
    @ 2025-4-2 11:36:25
    • 贪心,按照最晚下落时间点升序,下落时长降序排序,依次停放,对拍 wa了。

    • 观察数据范围:N≤10,枚举所有排列,判断是否有合法的排列,复杂度 O(n!nt)O(n !*n * t) ,3e8的计算量大概1s,题目限制2s,稳!

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e6 + 10, INF = 0x3f3f3f3f;
    struct T {
        int t, d, l;
        bool operator<(const T& r) const {
            if (t + d != r.t + r.d)
                return t + d < r.t + r.d;
            return l < r.l;
        }
    } t[N];
    
    int main1() {
        int T, n, a, b, c;
        scanf("%d", &T);
        while (T--) {
            scanf("%d", &n);
            for (int i = 1; i <= n; i++) {
                scanf("%d%d%d", &a, &b, &c);
                t[i] = {a, b, c};
            }
            sort(t + 1, t + 1 + n);
            int te = t[1].t + t[1].l, f = 1;
            for (int i = 2; i <= n; i++) {
                if (te > t[i].t + t[i].d) {
                    f = 0;
                    break;
                }
                if (te < t[i].t)
                    te = t[i].t;
                te += t[i].l;
            }
            printf("%s\n", f ? "YES" : "NO");
        }
        return 0;
    }
    
    int p[N];
    int main() {
        int T, n, a, b, c;
        scanf("%d", &T);
        while (T--) {
            scanf("%d", &n);
            for (int i = 1; i <= n; i++) {
                scanf("%d%d%d", &a, &b, &c);
                t[i] = {a, b, c}, p[i] = i;
            }
            int te = 0, f = 1;
            do {
                te = 0, f = 1;
                for (int j = 1; j <= n; j++) {
                    int i = p[j];
                    if (te > t[i].t + t[i].d) {
                        f = 0;
                        break;
                    }
                    if (te < t[i].t)
                        te = t[i].t;
                    te += t[i].l;
                }
                if (f)
                    break;
            } while (next_permutation(p + 1, p + 1 + n));
            printf("%s\n", f ? "YES" : "NO");
        }
        return 0;
    }
    
    • 1

    信息

    ID
    2026
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    2
    已通过
    1
    上传者