Loading

HDU 1071 The Area

Problem Description
Ignatius bought a land last week, but he didn’t know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?

Note: The point P1 in the picture is the vertex of the parabola.

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
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
For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

Sample Input
2
5.000000 5.000000
0.000000 0.000000
10.000000 0.000000
10.000000 10.000000
1.000000 1.000000
14.000000 8.222222

Sample Output
33.33
40.69

Hint
For float may be not accurate enough, please use double instead of float.

解决策略:算出抛物线和直线方程暴力积分之~

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <utility>
#include <queue>
#include<iostream>
#include<math.h>
#define MAX 500005
using namespace std;
struct point{
double x,y;
};
int main(){
 //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
 point p1,p2,p3;
 int t;
 cin>>t;
 double a,b,c,k,d;
 double res;
 while(t--){
    cin>>p1.x>>p1.y;
    cin>>p2.x>>p2.y;
    cin>>p3.x>>p3.y;
    a=(p2.y-p1.y)/pow((p2.x-p1.x),2.0);
    b=-2.0*p1.x*a;
    c=p1.x*p1.x*a+p1.y;
    k=(p3.y-p2.y)/(p3.x-p2.x);
    d=p2.y-k*p2.x;

    double x,res1,res2;
    x=p3.x;
    res1=a/3.0*pow(x,3.0)+(b-k)/2.0*x*x+(c-d)*x;
    x=p2.x;
    res2=a/3.0*pow(x,3.0)+(b-k)/2.0*x*x+(c-d)*x;
    printf("%.2f\n",res1-res2);
 }
 return 0;
}
posted @ 2015-07-25 16:57  SunStriKE  阅读(11)  评论(0编辑  收藏  举报  来源