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\n",a,b,c);
        //printf("%.4f %.4f %.4f\n",th,f1,f2);        
        double x=sqrt(f1*f2/2);        
        printf("%.4f\n",2*sin(th/2)*x);
    }
}

转载于:https://www.cnblogs.com/herumw/p/9464864.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值