拿到题的第一想法,又是一道水题,知道P1、P2、P3三点的坐标,就能够确定抛物线的公式。确定抛物线的公式就能够进行积分,然后就没有然后了。纯粹的数学题。
#include<iostream> using namespace std; int main() { double x1,y1,x2,y2,x3,y3,a,b,c,s; int n; while(cin>>n&&n) { for(int i=0;i<n;i++) { cin>>x1>>y1; cin>>x2>>y2; cin>>x3>>y3; a = ((y2-y1)*(x3-x2)/(x2-x1)-(y3-y2))/((x2*x2-x1*x1)*(x3-x2)/(x2-x1)-(x3*x3-x2*x2)); b = ((y2-y1)-a*(x2*x2-x1*x1))/(x2-x1); c = y1-a*x1*x1-b*x1; s = (a/3*x3*x3*x3+b/2*x3*x3+c*x3)-(a/3*x2*x2*x2+b*x2*x2/2+c*x2)-(y3+y2)*(x3-x2)/2; printf("%.2lf\n",s); } } return 0; }
原文:http://www.cnblogs.com/cynchanpin/p/7225891.html