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 @   SunStriKE  阅读(15)  评论(0编辑  收藏  举报  
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 百万级群聊的设计实践
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
点击右上角即可分享
微信分享提示