HDU 1071 - The area
Easy Math Problems -_-
Output the area of the shadow area.
The consuming key point exsists in how to caculate a, b, c.
kind of easy, as long as you just go ahead without considering the complexity of your expression.
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
void fMain() {
double x1, y1, x2, y2, x3, y3;
double a, b, c, k, b1, s;
//y=a*x*x+b*x+c;
//y=k*x+b2;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
k = (y3 - y2) / (x3 - x2);
b1 = y3 - k * x3;
a = ((x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1)) / ((pow(x3, 2) - pow(x2, 2)) * (x2 - x1) - (pow(x2, 2) - pow(x1, 2)) * (x3 - x2));
b = ((y2 - y1) - a * (pow(x2, 2) - pow(x1, 2))) / (x2 - x1);
c = y1 - a * pow(x1, 2) - b * x1;
s = a / 3 * (pow(x3, 3) - pow(x2, 3)) + (b - k) / 2 * (pow(x3, 2) - pow(x2, 2)) + (c - b1) * (x3 - x2);
printf("%.2lf\n", s);
}
int main() {
int n;
char temp;
scanf("%d", &n);
scanf("%c", &temp);
while(n--) {
fMain();
}
}
。。