题目:
三维空间中有N个点,每个点可能是三种颜色的其中之一,三种颜色分别是红绿蓝,分别用’R’, ‘G’, 'B’表示。
现在要找出三个点,并组成一个三角形,使得这个三角形的面积最大。
但是三角形必须满足:三个点的颜色要么全部相同,要么全部不同。
思路:
笨办法,利用海伦公式,各种点的组合逐个判断。
代码实现:
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
struct Point{
char c;
int x, y, z;
};
double count_triangle_area(const Point &a,const Point &b,const Point &c){
double area = -1;
double side[3];//存储三条边的长度;
side[0] = sqrt(pow(a.x - b.x,2)+pow(a.y - b.y,2) + pow(a.z - b.z,2));
side[