原文链接

#include <iostream>
#include <math.h>
const double eps = 1e-6;
using namespace std;
struct node
{
double x, y;
double w;
}p[5];
double dis(node A,node B)
{
return sqrt(pow((A.x - B.x), 2) + pow((A.y-B.y),2));
}
bool equ(double A, double B)
{
if (fabs(A - B) < eps) return true;
return false;
}
double area(node A,node B, node C)
{
double len1 = dis(A, B), len2 = dis(B, C),len3 = dis(A,C);
double p = (len1 + len2 + len3) / 2;
return sqrt(p*(p-len1)*(p-len2)*(p-len3));
}
int main(int argc, char *argv[])
{
while (cin >> p[0].x >> p[0].y >> p[0].w)
{
for (int i = 1; i < 3; i++)
{
cin >> p[i].x >> p[i].y >> p[i].w;
}
cin >> p[3].x >> p[3].y;
for (int i = 3; i >= 0; i--)
{
p[i].x -= p[0].x;
p[i].y -= p[0].y;
}
if (equ(area(p[0],p[1],p[2]),area(p[0],p[1],p[3])+area(p[0],p[2],p[3])+area(p[1],p[2],p[3])) == false)
{
cout << "-1" << endl;
continue;
}
#if 0
double B = (p[1].x*p[3].y - p[3].x*p[1].y) / (p[1].x*p[2].y - p[2].x*p[1].y);
double A;
if (equ(p[1].x, 0) == false) A = (p[3].x - B*p[2].x) / p[1].x;
else A = (p[3].y - B*p[2].y) / p[1].y;
printf("%.2f\n", A*p[1].w + B*p[2].w + (1.0 - A - B)*p[0].w);
#else
double B = (p[3].x*p[2].y - p[2].x*p[3].y) / (p[1].x*p[2].y - p[2].x*p[1].y);
double A;
if (equ(p[2].x, 0) == false) A = (p[3].x - B*p[1].x) / p[2].x;
else A = (p[3].y - B*p[1].y) / p[2].y;
printf("%.2f\n", A*p[2].w + B*p[1].w + (1.0 - A - B)*p[0].w);
#endif
}
return 0;
}