zoukankan      html  css  js  c++  java
  • hdu 1352 I Conduit!

    计算几何,主要是排序问题,其他都很好做……

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<iomanip>
    #include<cmath>
    #include<string>
    using namespace std;
    struct
    seg
    {

        double
    k,b;
        double
    x1,y1;
        double
    x2,y2;
        bool
    flag;
    }
    an[10002];
    int
    same(double a,double b)
    {

        if
    (fabs(a-b)>1e-8) return 0;
        return
    1;
    }

    bool
    less(double a,double b)
    {

        if
    (a-b>1e-8) return 0;
        return
    1;
    }

    bool
    cmp(const seg &a,const seg &b)
    {

        if
    (a.flag!=b.flag) return a.flag<b.flag;
        if
    (a.flag)
        {

            if
    (!same(a.k,b.k)) return less(a.k,b.k);
            if
    (same(a.b,b.b)) return less(a.x1,b.x1);
            return
    less(a.b,b.b);
        }

        else

        {

            if
    (!same(a.x1,b.x1)) return less(a.x1,b.x1);
            return
    less(a.y1,b.y1);
        }
    }

    double
    MAX(double a,double b)
    {

        if
    (a-b>1e-10) return a;
        return
    b;
    }

    int
    fun(seg &a,seg &b)
    {

        if
    (a.flag!=b.flag) return 0;
        if
    (a.flag)
        {

            if
    (!same(a.k,b.k)) return 0;
            if
    (!same(a.b,b.b)) return 0;
            if
    (b.x1-a.x2>1e-8) return 0;
            b.x2=MAX(a.x2,b.x2);
            return
    1;
        }

        else

        {

            if
    (same(a.x1,b.x1))
            {

                if
    (b.y1-a.y2<1e-8)
                {

                    b.y2=MAX(b.y2,a.y2);
                    return
    1;
                }
            }

            return
    0;
        }
    }

    int
    main()
    {

        int
    b,c,n,m,i,j;
        double
    x1,x2,y1,y2;
        bool
    flag;
        while
    (cin>>n&&n)
        {

            memset(an,0,sizeof(an));
            for
    (i=0;i<n;i++)
            {

                cin>>an[i].x1>>an[i].y1>>an[i].x2>>an[i].y2;  
                if
    (an[i].x1==an[i].x2)
                {

                    an[i].flag=0;
                    if
    (an[i].y1>an[i].y2) swap(an[i].y1,an[i].y2);
                }

                else

                {

                    an[i].flag=1;
                    if
    (an[i].x1>an[i].x2)
                    {

                        swap(an[i].x1,an[i].x2);
                        swap(an[i].y1,an[i].y2);
                    }

                    an[i].k=(an[i].y2-an[i].y1)/(an[i].x2-an[i].x1);
                    an[i].b=an[i].y1-an[i].k*an[i].x1;
                }
            }

            sort(an,an+n,cmp);
            m=1;
            for
    (i=1;i<n;i++)
            {

                if
    (!fun(an[i-1],an[i]))
                    m++;
            }

            cout<<m<<endl;
        }

        return
    0;
    }

  • 相关阅读:
    9个免费的桌面产品自动化测试工具
    How to wait for any one of the two element to appear on the screen?
    git仓库过大致使clone失败的解决方法
    Maven项目打包出现:No compiler is provided in this environment. Perhaps you are running on a JRE rather than JDK
    eclipse java maven testng The import org.testng cannot be resolved
    Codeforces Round #165 (Div. 1) B 269B Greenhouse Effect
    Codeforces Round #162 (Div. 1) B 264B Good Sequences
    HDU 4512 HDOJ 吉哥系列故事——完美队形I 腾讯2013初赛第三场
    HDU 4483 HDOJ Lattice triangle
    第二届腾讯校园编程马拉松参赛感想 极限!马拉松
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3198494.html
Copyright © 2011-2022 走看看