zoukankan      html  css  js  c++  java
  • 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++
    ",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
  • 相关阅读:
    【loj2639】[Tjoi2017]不勤劳的图书管理员
    【bzoj3514】Codechef MARCH14 GERALD07加强版
    BZOJ1002【FJOI2007】轮状病毒
    数论基础(附加例题)
    表达式总结
    背包
    hdu1027
    hdu1026
    hdu1025
    hdu1024
  • 原文地址:https://www.cnblogs.com/yours1103/p/3847648.html
Copyright © 2011-2022 走看看