码迷,mamicode.com
首页 > 其他好文 > 详细

uva 1421

时间:2014-07-16 17:47:10      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   art   

稍微有点新意的二分

bubuko.com,布布扣
#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

 

 

uva 1421,布布扣,bubuko.com

uva 1421

标签:style   blog   http   color   os   art   

原文地址:http://www.cnblogs.com/yours1103/p/3847648.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!