Description
Note: The point P1 in the picture is the vertex of the parabola.
Input
Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).
Output
Sample Input
Sample Output
題意:給你三個點的座標,求面積。
思路:額,沒想到好的,強行解三元一次方程組把a,b,c解出來,再利用積分求解。。
這個更簡單,拋物線頂點座標表示公式:y=a(x-x1)^2+y1,代入x2或x3座標可解得拋物線公式,再利用x2,x3,解y=kx+b,積分就可以了。
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iostream>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
void swap(double *a,double *b){ //遇到除以零的情況時,兩行交換位置
double t;
t=*a;
*a=*b;
*b=t;
}
int main(){
freopen("input.txt","r",stdin);
int t;
cin>>t;
while(t--){
double a,b,c,u,v,uy,vy;
double x1,y1,x2,y2,x3,y3,x1_2,x2_2,x3_2,m1=1,m2=1,m3=1;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
u=x2;uy=y2;
v=x3;vy=y3;
x1_2=x1*x1;
x2_2=x2*x2;
x3_2=x3*x3;
if(x1_2==0){
swap(&x1_2,&x2_2);
swap(&x1,&x2);
swap(&m1,&m2);
swap(&y1,&y2);
}
x2=x2-x2_2/x1_2*x1;
m2=m2-x2_2/x1_2*m1;
y2=y2-x2_2/x1_2*y1;
// printf("x2=%.2f\nm2=%.2f\ny2=%.2f\n",x2,m2,y2);
if(x1_2==0){
swap(&x1_2,&x2_2);
swap(&x3,&x2);
swap(&m3,&m2);
swap(&y3,&y2);
}
x3=x3-x3_2/x1_2*x1;
m3=m3-x3_2/x1_2*m1;
y3=y3-x3_2/x1_2*y1;
// printf("x3=%.2f\nm3=%.2f\ny3=%.2f\n",x3,m3,y3);
if(x2==0){
swap(&x3,&x2);
swap(&m3,&m2);
swap(&y3,&y2);
}
m3=m3-x3/x2*m2;
y3=y3-x3/x2*y2;
// printf("m3=%.2f\ny3=%.2f\n",m3,y3);
c=y3/m3;
b=(y2-m2*c)/x2;
a=(y1-m1*c-x1*b)/x1_2;
// printf("a=%.2f\nb=%.2f\nc=%.2f\n",a,b,c);
double S,S1,S2;
S1=(a/3*v*v*v+b/2*v*v+c*v)-(a/3*u*u*u+b/2*u*u+c*u);
// printf("S1=%.2f\n",S1);
S2=(uy+vy)*(v-u)/2.0;
// printf("S2=%.2f\n",S2);
printf("%.2f\n",S1-S2);
}
return 0;
}