Triangle Fun - UVa 11437 几何

Triangle Fun 
Input: 
Standard Input

Output: Standard Output

 

In the picture below you can see a triangle ABC. Point D, E and F divides the sides BC, CA and AB into ratio 1:2 respectively. That is CD=2BD, AE=2CE and BF=2AF. A, D; B, E and C, F are connected. AD and BE intersects at P, BE and CF intersects at Q and CF and AD intersects at R.

So now a new triangle PQR is formed. Given triangle ABC your job is to find the area of triangle PQR.

 

Input

First line of the input file contains an integer N (0<N<1001) which denotes how many sets of inputs are there. Input for each set contains six floating-point number Ax, Ay, Bx, By, Cx, Cy. (0≤Ax, Ay, Bx, By, Cx,Cy ≤10000) in one line line. These six numbers denote that the coordinate of points A, B and C are (Ax, Ay), (Bx, By) and (Cx, Cy) respectively. A, B and C will never be collinear.

 

Output

For each set of input produce one line of output. This one line contains an integer AREA. Here AREA is the area of triangle PQR, rounded to the nearest integer.

 

Sample Input

2

3994.707 9251.677 4152.916 7157.810 5156.835 2551.972

6903.233 3540.932 5171.382 3708.015 213.959 2519.852

 

Output for Sample Input

98099

206144

 




题意:已知DEF分别是三等分点,已知ABC的坐标,问Srpq的面积。

思路:Srpq的面积为Sabc的面积的1/7。证明如下:连接DE,Sabe:Sdbe=2/3:1/9=6:1,所以AP:DP=6:1,Spde=Sade/7=4/9 /7=4/63,所以Sbdp=Sbde-Spde=1/9-4/63=1/21。Srpq=1-(Sabd-bdq)*3=1/7。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
double x[3],y[3],length[3],p,ans;

int main()
{
    int T,t,i,j,k;
    scanf("%d",&T);
    for(t=1;t<=T;t++)
    {
        for(i=0;i<=2;i++)
           scanf("%lf%lf",&x[i],&y[i]);
        for(i=0;i<=2;i++)
           length[i]=sqrt((x[i]-x[(i+1)%3])*(x[i]-x[(i+1)%3])+(y[i]-y[(i+1)%3])*(y[i]-y[(i+1)%3]));
        p=0;
        for(i=0;i<=2;i++)
           p+=length[i];
        p/=2;
        ans=sqrt(p*(p-length[0])*(p-length[1])*(p-length[2]));
        printf("%.0f\n",ans/7);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值