杭电acm the area
这题直接使用积分的方法来做,不需要考虑交叉点和顶点重合的情况:
不能使用float作为变量,否则一直wa
#include<iostream> #include<cstdio> using namespace std; int main(){ int t; scanf("%d",&t); while(t--){ double x1,y1,x2,y2,x3,y3; cin>>x1>>y1>>x2>>y2>>x3>>y3; double k = (y3-y2)/(x3-x2); double m = y2-k*x2; double k1=(y2-y1)/((x2-x1)*(x2-x1)); double a = k1; double b = -2*a*x1; double c = a*x1*x1+y1; double s = a/3*(x3*x3*x3-x2*x2*x2)+ 0.5*(b-k)*(x3*x3-x2*x2)+(c-m)*(x3-x2); printf("%.2f\n",s); } }