#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define eps 1e-6
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)>(y)?(y):(x))
using namespace std;
struct node
{
double l,r,h;
}line[5050];
int n;
int ok(double x)
{
double L=atan2(line[0].h,line[0].r-x);
double R=atan2(line[0].h,line[0].l-x);
for(int i=1;i<n;i++)
{
double L1=atan2(line[i].h,line[i].r-x);
double R1=atan2(line[i].h,line[i].l-x);
if(L-R1>eps)
return -1;
if(L1-R>eps)
return 1;
L=MAX(L,L1);
R=MIN(R,R1);
}
return 0;
}
bool cmp(const node &a,const node &b)
{
return a.h<b.h;
}
int main()
{
int T;
double w;
scanf("%d",&T);
while(T--)
{
scanf("%lf%d",&w,&n);
for(int i=0;i<n;i++)
scanf("%lf%lf%lf",&line[i].h,&line[i].l,&line[i].r);
sort(line,line+n,cmp);
double l=0,r=w;
int flag=0;
while(r-l>eps)
{
double m=(l+r)/2;
int t=ok(m);
if(t==1)
l=m;
else
if(t==-1)
r=m;
else
{
flag=1;
break;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}
uva 1421 Archery
最新推荐文章于 2020-03-16 23:52:54 发布