• FZU2110 Star【计算几何】


    Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.

    Input

    The first line of the input contains an integer T (T≤10), indicating the number of test cases.

    For each test case:

    The first line contains one integer n (1≤n≤100), the number of stars.

    The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.

    Output

    For each test case, output an integer indicating the total number of different acute triangles.

    Sample Input

    1
    3
    0 0
    10 0
    5 1000
    

    Sample Output

    1

    本来想用算夹角的函数的,还特意去找了一下模板

    后来应该是因为精度WA了

    才发现其实只用判断一下边之间的关系就可以判断是不是锐角三角形了

    emmm题目的意思还要学会转换

    判断锐角三角形:

    A^2 + B^2 < C^2 就是锐角三角形

    算夹角的模板:【没有精度判断】

    double getAngle(Point p1, Point p2, Point p3)
    {
        double angle = 0.0;
        Point va, vb;
        va.x = p2.x - p1.x;
        va.y = p2.y - p1.y;
        vb.x = p3.x - p1.x;
        vb.y = p3.y - p1.y;
    
        double productValue = va.x * vb.x + va.y * vb.y;
        double vaVal = sqrt(va.x * va.x + va.y * va.y);
        double vbVal = sqrt(vb.x * vb.x + vb.y * vb.y);
        double cosVal = productValue / (vaVal * vbVal);
    
        if(cosVal < -1 && cosVal > -2){
            cosVal = -1;
        }
        else if(cosVal > 1 && cosVal < 2){
            cosVal = 1;
        }
    
        angle = acos(cosVal) * 180 / PI;
        return angle;
    }



    #include <iostream>
    #include <algorithm>
    #include <cstring>
    
    #include <cstdio>
    
    #include <cmath>
    
    using namespace std;
    #define PI 3.1415926
    #define EPS 1.0e-6
    
    
    
    struct Point {
        Point(){}
        Point(double x, double y):x(x), y(y){}
        double x,y;
    
    };
    struct Line{
        Point st, ed;
    };
    
    double getAngle(Point p1, Point p2, Point p3)
    {
        double angle = 0.0;
        Point va, vb;
        va.x = p2.x - p1.x;
        va.y = p2.y - p1.y;
        vb.x = p3.x - p1.x;
        vb.y = p3.y - p1.y;
    
        double productValue = va.x * vb.x + va.y * vb.y;
        double vaVal = sqrt(va.x * va.x + va.y * va.y);
        double vbVal = sqrt(vb.x * vb.x + vb.y * vb.y);
        double cosVal = productValue / (vaVal * vbVal);
    
        if(cosVal < -1 && cosVal > -2){
            cosVal = -1;
        }
        else if(cosVal > 1 && cosVal < 2){
            cosVal = 1;
        }
    
        angle = acos(cosVal) * 180 / PI;
        return angle;
    }
    
    
    int dblcmp(double r) {
    
        if(fabs(r)<EPS) return 0;
    
        return r>0?1:-1;
    
    }
    
    double cross(Point p1, Point p2, Point p3, Point p4)
    {
        return (p2.x - p1.x) * (p4.y - p3.y) - (p2.y - p1.y) * (p4.x - p3.x);
    }
    
    double area(Point p1, Point p2, Point p3)
    {
        return cross(p1, p2, p1, p3);
    }
    
    double farea(Point p1, Point p2, Point p3)
    {
        return fabs(area(p1, p2, p3));
    }
    
    bool meet(Point p1, Point p2, Point p3, Point p4)
    {
        return max(min(p1.x, p2.x), min(p3.x, p4.x)) <= min(max(p1.x, p2.x), max(p3.x, p4.x))
        && max(min(p1.y, p2.y), min(p3.y, p4.y)) <= min(max(p1.y, p2.y), max(p3.y, p4.y))
        && dblcmp(cross(p3, p2, p3, p4) * cross(p3, p4, p3, p1)) >= 0
        && dblcmp(cross(p1, p4, p1, p2) * cross(p1, p2, p1, p3)) >= 0;
    }
    
    Point inter(Point p1, Point p2, Point p3, Point p4)
    {
        double k = farea(p1, p2, p3) / farea(p1, p2, p4);
        return Point((p3.x + k * p4.x) / (1 + k), (p3.y + k * p4.y) / (1 + k));
    }
    
    bool sharpTri(Point p1, Point p2, Point p3)
    {
        double edge[3];
        edge[0] = (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
        edge[1] = (p1.x - p3.x) * (p1.x - p3.x) + (p1.y - p3.y) * (p1.y - p3.y);
        edge[2] = (p2.x - p3.x) * (p2.x - p3.x) + (p2.y - p3.y) * (p2.y - p3.y);
    
        sort(edge, edge + 3);
        if(edge[2] < edge[1] + edge[0] + EPS){
            return true;
        }
        else return false;
    }
    
    int n;
    Point star[105];
    
    int main() {
    
        int t;
        cin>>t;
        while(t--){
            scanf("%d", &n);
            for(int i = 0; i < n; i++){
                scanf("%lf%lf", &star[i].x, &star[i].y);
            }
            int cnt = 0;
            for(int i = 0; i < n - 2; i++){
                for(int j = i + 1; j < n - 1; j++){
                    for(int k = j + 1; k < n; k++){
                        //cout<<getAngle(star[i], star[j], star[k])<<endl;
                        if(sharpTri(star[i], star[j], star[k])) cnt++;
                    }
                }
            }
            cout<<cnt<<endl;
        }
    
        return 0;
    
    }
    



  • 相关阅读:
    Jmeter混合场景压力测试
    数据驱动DDT(Data-Driven Tests):测试数据的参数化
    运用TextSuite和TestRunner运行测试脚本
    Test Fixture框架结构
    解决appium-doctor报各种 cannot be found问题
    搭建python+appium环境的时候遇到 'could not find adb.exe!'的问题
    Python appium搭建app自动化测试环境
    夜神模拟器查看APP的activity等信息
    [leetcode 23]Merge k Sorted Lists
    [leetcode 22]generate parentheses
  • 原文地址:https://www.cnblogs.com/wyboooo/p/9643414.html
Copyright © 2020-2023  润新知