• 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);
        }
    }

  • 相关阅读:
    Django笔记(2)Json字段处理
    jvm 启动参数设置(转载)
    消息中间件及WebSphere MQ入门(转载)
    Ubuntu下Tomcat绑定80端口(zz)
    idea+tomcat 端口占用
    内存溢出和内存泄漏的区别(ZZ)
    Ubuntu上搭建Hadoop环境(单机模式+伪分布模式) (转载)
    ubuntu 安装jdk7小结(转载)
    ubuntu下安装maven(转载)
    CXF wsdl2java (转载)
  • 原文地址:https://www.cnblogs.com/herumw/p/9464864.html
Copyright © 2020-2023  润新知