uva1421

#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 5005;
const double ex = 1e-7;
int w,n;
struct Node {
	double d, l, r;
	bool operator<(const Node& input) {
		return d < input.d;
	}
}node[maxn];

int check(double x) {
	double l = atan2(node[0].d, node[0].r - x), r = atan2(node[0].d, node[0].l - x);
	for (int i = 1; i < n; i++) {
		double ll = atan2(node[i].d, node[i].r - x);
		double rr = atan2(node[i].d, node[i].l - x);
		//当前角度太大了 需要右移变小
		if (ll - r > ex) return 1;
		//当前角度太小了 需要左移变大
		if (rr - l < -ex) return -1;
		l = max(ll, l);
		r = min(rr, r);
	}
	//可穿
	return 0;
}
bool IsOk() {
	double l = 0, r = w;
	while (r - l > ex) {
		double mid = (r + l) / 2;
		int ret = check(mid);
		if (ret == 0)return true;
		else if (ret == 1) l = mid;
		else r = mid;
	}
	return false;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> w >> n;
		for (int i = 0; i < n; i++) {
			cin >> node[i].d >> node[i].l >> node[i].r;
		}
		sort(node, node + n);

		if (IsOk())cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值