您的位置:首页 > 其它

HDU 1071 - The area

2015-07-22 11:22 337 查看

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();
}
}


。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: