zoukankan      html  css  js  c++  java
  • Triangle

    Problem Description
    This is a simple question, give you a triangle, please divide the triangle into two parts with a segment. These two parts should have the same area, and the segment should be as short as possible. Please calculate the length of the segment.
     

    Input
    The first line of the input is the number T(T<=100), which is the number of cases followed. For each test case, the only line contains space-separated integers x1, y1, x2, y2, x3, y3,the coordinates of triangle endpoint. The absolute value of all the coordinates will not be more than 109.
     

    Output
    For each test case, output only one line, containing the length of segment only. Your answer should be rounded to 4 digits after the decimal point.
     

    Sample Input
    1 0 0 10 0 0 10
     

    Sample Output
    6.4359

    因为要分割为两个面积相等的两部分,而且要使分割线最小,所以选择最小顶点多对应的分割线,这样分割线会最短。而且分割后得到的三角形是等腰三角形。
    先找出最小边,然后把其对应的角的cos值算出来,然后再算出等腰三角形的腰,最后算出分割线的长。
    #include<stdio.h>
    #include<math.h>
    double f1,f2,a1,a2,a3,b1,b2,b3;
    int cas;
    int main(){
        scanf("%d",&cas);
        int casno=0;
        while(cas--){
            scanf("%lf%lf%lf%lf%lf%lf",&a1,&b1,&a2,&b2,&a3,&b3);
            double a=sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
            double b=sqrt((a1-a3)*(a1-a3)+(b1-b3)*(b1-b3));
            double c=sqrt((a3-a2)*(a3-a2)+(b3-b2)*(b3-b2));
            double th;
            if(a<=b&&a<=c){
                th=acos(-(a*a-b*b-c*c)/2/b/c);
                f1=b,f2=c;
            }else if(b<=a&&b<=c){
                th=acos(-(b*b-a*a-c*c)/2/a/c);
                f1=a,f2=c;
            }else {
                th=acos(-(c*c-a*a-b*b)/2/a/b);
                f1=a,f2=b;
            }
            //printf("%.4f %.4f %.4f
    ",a,b,c);
            //printf("%.4f %.4f %.4f
    ",th,f1,f2);        
            double x=sqrt(f1*f2/2);        
            printf("%.4f
    ",2*sin(th/2)*x);
        }
    }

  • 相关阅读:
    个人作业——软件评测
    结对第二次作业
    寒假作业(2/2)
    寒假作业(1/2)
    markdown整理
    我们一定会在人生的更高处相见的
    时间复杂度 分析 可能算法
    有关数学 结论 规律 题目 小结
    jzyz 题库 选做 及 知识小结
    隔板法
  • 原文地址:https://www.cnblogs.com/herumw/p/9464864.html
Copyright © 2011-2022 走看看