Input:输入多组数据,每组输入三行,每行给出一个顶点的x,y坐标,中间以空格分隔。
Output:输出三角形最大边的边长。 边长取整
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
typedef struct SPoint
{
int x;
int y;
}SPoint;
typedef struct Triangle
{
SPoint A;
SPoint B;
SPoint C;
}Triangle;
// 计算参数x的平方根的倒数
static float InvSqrt(float x)
{
float xhalf = 0.5f * x;
int i = *(int*)&x;
i = 0x5f3759df - (i >> 1); // 计算第一个近似根
x = *(float*)&i;
x = x * (1.5f - xhalf * x * x); // 牛顿迭代法
x = x * (1.5f - xhalf * x * x);
x = x * (1.5f - xhalf * x * x);
return x;
}
static double GetLength(SPoint p1, SPoint p2)
{
float dx, dy;
// 计算长度
}
static bool CheckTriangle(Triangle T1)
{
float K1, K2, K3;
// 排除水平垂直线
// 计算斜率
return eq == false;// 判断斜率是否相等
}
static Triangle T1;
int main()
{
// 输入参数解析,并赋值
T1.A.x = 0;T1.A.y = 0;
T1.B.x = 1;T1.B.y = 1;
T1.C.x = 2;T1.C.y = 0;
if (CheckTriangle(T1) == false)
{
printf("不是三角形");
return 0;
}
double Edges[3] ={0};// 计算三边长度
Edges[0] = GetLength(T1.A, T1.B);
Edges[1] = GetLength(T1.A, T1.C);
Edges[2] = GetLength(T1.B, T1.C);
double MaxEdge = -1;
// 查找最大值
printf("最大边长为:%f\n",MaxEdge);
return 0;
}