uva 1421

稍微有点新意的二分

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#define eps 0.000001
#define maxn 5005
using namespace std;
int n;
double w;
struct node
{
    double x,y,d;
    bool operator<(const node &t)const
    {
        return d<t.d;
    }
} no[maxn];

int get(double x)
{
    double ll=atan2(no[0].d,no[0].y-x),rr=atan2(no[0].d,no[0].x-x);
    for(int i=1;i<n;i++)
    {
        double l=atan2(no[i].d,no[i].y-x);
        double r=atan2(no[i].d,no[i].x-x);
//        printf("%lf %lf++\n",l,r);
        if(l-rr>eps)return 1;
        if(r-ll<-eps)return -1;
        ll=max(ll,l);
        rr=min(rr,r);
    }
    return 0;
}

bool solve()
{
    double l=0.0,r=w;
    while(r-l>eps)
    {
        double mid=(r+l)/2.0;
        int k=get(mid);
        if(k==0)return 1;
        else if(k==1)l=mid;
        else r=mid;
    }
    return 0;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf",&w);
        scanf("%d",&n);
        for(int i=0; i<n; i++)
        {
            scanf("%lf%lf%lf",&no[i].d,&no[i].x,&no[i].y);
        }
        sort(no,no+n);

        if(solve())puts("YES");
        else puts("NO");
    }
    return 0;
}
View Code

 

 

posted @ 2014-07-15 23:11  Yours1103  阅读(140)  评论(0编辑  收藏  举报