给定平面上任意三个点的坐标(x1,y1) (x2,y2) (x3,y3)
输入格式:
输入在一行中顺序给出六个[−100,100]范围内的数字,即三个点的坐标
x1 y1 x2 y2 x3 y3
输出格式:
若这3个点不能构成三角形,则在一行中输出“Impossible”;若可以,则在一行中输出该三角形的周长和面积,格式为“L = 周长, A = 面积”,输出到小数点后2位。
输入样例1:
4 5 6 9 7 8
输出样例1:
L = 10.13, A = 3.00
输入样例2:
4 6 8 12 12 18
输出样例2:
Impossible
#include <stdio.h>
#include <math.h>
int main()
{
double x1,y1,x2,y2,x3,y3;
scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
double t1 = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
double t2 = (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3);
double t3 = (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3);
double L = sqrt(t1) + sqrt(t2) + sqrt(t3);
double A = sqrt(4*t1*t2-(t1+t2-t3)*(t1+t2-t3)) / 4.0;
if(x1==x2||x2==x3||x1 == x3)
{
if(x1 == x2&& x2 == x3)
printf("Impossible");
else
printf("L = %.2lf,A = %.2lf", L, A);
}
else
{
if((y2-y1)*(x3-x1) == (y3-y1)*(x2-x1))
{
printf("Impossible");
}
else
{
printf("L = %.2lf,A = %.2lf", L, A);
}
}
return 0;
}