LA4253(暴力 + 枚举)

题目:LA4253
思路:不会做,思路来自于此博客

思路都是最难的,具体的代码很简答:

#include <iostream>
#include <algorithm>
#define db double

using namespace std;

const int maxn = 5000 + 10;
const db eps = 1e-11;
int n, w;

struct node {
    db h, l, r;
    bool operator < (const node &a) const {
    return h > a.h;
    }

}A[maxn];

bool ok() {
    db l = 0, r = w, ll, rr;
    for (int i = 1; i <  n; i ++) {
        if (A[0].r == A[i].l) {
            ll = A[0].r;
        } else {
            ll = (A[0].r * A[i].h - A[i].l * A[0].h) / (A[i].h - A[0].h);
        }

        if (A[0].l == A[i].r) {
            rr = A[0].l;
        } else {
            rr = (A[0].l * A[i].h - A[i].r * A[0].h) / (A[i].h - A[0].h);
        }
        l = max(l, ll);
        r = min(r, rr);
    }
    return r >= l;
}

int main(){
    freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout);

    int T; scanf("%d", &T);
    while (T --) {
        scanf("%d %d", &w, &n);
        for (int i = 0; i < n; i ++)
            scanf("%lf %lf %lf", &A[i].h, &A[i].l, &A[i].r);
        sort(A, A + n);
        if (ok()) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值