zoukankan      html  css  js  c++  java
  • hdu-5784 How Many Triangles(计算几何+极角排序)

    题目链接:

    How Many Triangles

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 570    Accepted Submission(s): 183


    Problem Description
    Alice has n points in two-dimensional plane. She wants to know how many different acute triangles they can form. Two triangles are considered different if they differ in at least one point.
     
    Input
    The input contains multiple test cases.
    For each test case, begin with an integer n,
    next n lines each contains two integers xi and yi.
    3n2000
    0xi,yi1e9
    Any two points will not coincide.
     
    Output
    For each test case output a line contains an integer.
     
    Sample Input
     
    3
    1 1
    2 2
    2 3
    3
    1 1
    2 3
    3 2
    4
    1 1
    3 1
    4 1
    2 3
     
    Sample Output
     
    0
    1
    2
     
    题意:
     
    问有多少个锐角三角形,跟以前的求钝角和直角三角形一样,要用极角排序,不过这道题的点有共线的,所以要结合一下三角形的知识,其实就是锐角三角形三个锐角,直角和钝角三角形有两个锐角,求出锐角的个数,钝角和直角的个数,然后锐角个数减去两倍的直角钝角个数,再除3就是答案了,极角排序的问题就是精度问题了;精度ep开的小一点啦就能过啦;
     
    思路:
     
    哎哟,上边一不小心就说了;
     
    AC代码;
     
    /************************************************
    ┆  ┏┓   ┏┓ ┆   
    ┆┏┛┻━━━┛┻┓ ┆
    ┆┃       ┃ ┆
    ┆┃   ━   ┃ ┆
    ┆┃ ┳┛ ┗┳ ┃ ┆
    ┆┃       ┃ ┆ 
    ┆┃   ┻   ┃ ┆
    ┆┗━┓    ┏━┛ ┆
    ┆  ┃    ┃  ┆      
    ┆  ┃    ┗━━━┓ ┆
    ┆  ┃  AC代马   ┣┓┆
    ┆  ┃           ┏┛┆
    ┆  ┗┓┓┏━┳┓┏┛ ┆
    ┆   ┃┫┫ ┃┫┫ ┆
    ┆   ┗┻┛ ┗┻┛ ┆      
    ************************************************ */ 
     
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
     
    using namespace std;
     
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
     
    typedef  long long LL;
     
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
     
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=5e4+10;
    const int maxn=2e3+14;
    const double eps=1e-12;
    
    double temp[2*maxn];
    int n;
    struct node
    {
        double x,y;
    }po[maxn];
    
    int main()
    {      
            while(scanf("%d",&n)!=EOF)
            {
                For(i,1,n)
                {
                    scanf("%lf%lf",&po[i].x,&po[i].y);
                }
                LL ans1=0,ans2=0;
                For(i,1,n)
                {
                    int cnt=0;
                    For(j,1,n)
                    {
                        if(i==j)continue;
                        temp[++cnt]=atan2(po[j].y-po[i].y,po[j].x-po[i].x);
                        if(temp[cnt]<0)temp[cnt]+=2*PI;
                    }
                    sort(temp+1,temp+cnt+1);
                    For(j,1,cnt)
                    {
                        temp[j+cnt]=temp[j]+2*PI;
                    }
                    int l=1,r=1,le=1;
                    For(j,1,cnt)
                    {
                        while(temp[r]-temp[j]<PI&&r<=2*cnt)r++;
                        while(temp[l]-temp[j]<0.5*PI&&l<=2*cnt)l++;
                        while(temp[le]-temp[j]<=eps&&le<=2*cnt)le++;
                        ans1=ans1+r-l;
                        ans2=ans2+l-le;
                    }
                }
                cout<<(ans2-2*ans1)/3<<"
    ";
            }
            return 0;
    }
    

      

  • 相关阅读:
    Perl 正则匹配经验记录
    Linux——高效玩转命令行
    推荐一个SAM文件或者bam文件中flag含义解释工具
    单端测序(Single- ead)和双端测序(Pai ed-end和Mate-pai )的关系
    区别samtools faid产生的.fai文件功能和bwa index 产生的四个文件的功能
    Perl新接触的小命令
    Perl调用外部命令(其他脚本、系统命令)的方法和区别
    Linux——命令
    学习《Python金融实战》中文版PDF+英文版PDF+源代码
    学习《深度学习与计算机视觉算法原理框架应用》《大数据架构详解从数据获取到深度学习》PDF代码
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5733811.html
Copyright © 2011-2022 走看看