这道题需要用到三角形的面积公式,用二维向量的外积解决,0.5*|a叉乘b| = 0.5×|a|*|b|*sin(ab夹角) = 三角形的面积,判断一个点是不是在三角形里面或是在其边上,判断这个点和这个三角形的三个顶点形成的三个三角形的面积和是不是和大三角形的面积相等就行了,注意浮点数的比较不能用==,要用fabs。书上的基础题目终于做完了,有个别几道题一直wrong answer不知怎么回事,以后有时间再回来看,今天正式开始沿着书学正式的算法。下面是简单的推导和源代码:
#include <stdio.h>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
typedef double AREA;
typedef char NAME;
map< AREA, set<NAME> > result;
struct node
{
char name;
double x;
double y;
};
struct node arr[16];
int cmp(const void *a, const void *b)
{
return ((struct node*)a)->name - ((struct node*)b)->name;
}