hdu 1215 The area
算抛物线和直线解析式,简单积分
#include <iostream> #include<cstdio> using namespace std; double p2x,p2y,p1x,p1y,p3x,p3y; double a,b,c,a1,b1; double ans; void solve1() { //求直线 a1 = (p3y-p2y)/(p3x-p2x); b1 = (p2y - p2x*a1); //求抛物线解析式 double t1,t2,q1,q2,p1,p2; t1 = p2x*p2x - p1x*p1x; t2 = p1x*p1x - p3x*p3x; p1 = p2x-p1x; p2 = p1x-p3x; q1 = p2y-p1y; q2 = p1y-p3y; a = (q1*p2 - q2*p1)/(t1*p2-t2*p1); b = (q1-a*t1)/p1; c = p2y - (a*p2x*p2x + b*p2x); //求差方程解析式 b = b - a1; c = c - b1; //求积分 a = a/3; b = b/2; ans = (p2x*p2x*p2x*a) + (p2x*p2x*b) + (p2x*c); ans -=(p3x*p3x*p3x*a) + (p3x*p3x*b) + (p3x*c); ans = ans > 0?ans:-ans; } int main() { int cas; cin >> cas; while(cas --){ cin >> p1x>>p1y>>p2x>>p2y>>p3x>>p3y; solve1(); printf("%0.2f\n",ans); } return 0; }
时间: 2024-10-11 17:54:36