The area 积分积分

The area

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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

 1 #include <iostream>
 2 #include <math.h>
 3 #include <stdio.h>
 4 #include <string.h>
 5 using namespace std;
 6 struct point
 7 {
 8     double x,y;
 9 } p1,p2,p3;
10 double a,b,c,a1,b1;
11 double F(double x)
12 {
13     return fabs(a*(x-b)*(x-b)+c-a1*x-b1);
14 }
15 void init()
16 {
17     b = p1.x;
18     c = p1.y;
19     a = (p2.y - c) / (p2.x - b) / (p2.x - b);
20     a1 = (p3.y - p2.y) / (p3.x - p2.x);
21     b1 = p2.y - a1 * p2.x;
22     //cout<<a<<"   "<<b<<"    "<<c<<" "<<a1<<" "<<b1<<" "<<endl;
23 }
24 //三点辛普森公式
25 double simpson(double width,double fa,double fb,double fc)
26 {
27     return (fb+fa+4*fc)*width/6;
28 }
29
30 //自适应simpson公式递归过程
31 double asr(double a,double b,double eps,double A)
32 {
33     double c=(a+b)/2;
34     double fa,fb,fc,L,R;
35     fa=F(a);
36     fb=F(b);
37     fc=F(c);
38     L=simpson(c-a,fa,fc,F((c+a)/2));
39     R=simpson(b-c,fc,fb,F((b+c)/2));
40     if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15;
41     return asr(a,c,eps/2,L)+asr(c,b,eps/2,R);
42 }
43 double asr1(double a,double b,double eps)
44 {
45     return asr(a,b,eps,simpson(b-a,F(a),F(b),F((b+a)/2)));
46 }
47 int main()
48 {
49     int t;
50     scanf("%d",&t);
51     while(t--)
52     {
53         scanf("%lf%lf",&p1.x,&p1.y);
54         scanf("%lf%lf",&p2.x,&p2.y);
55         scanf("%lf%lf",&p3.x,&p3.y);
56         init();
57         printf("%.2lf\n",asr1(p2.x,p3.x,0.0000001));
58     }
59 }

The area 积分积分,布布扣,bubuko.com

时间: 2024-11-10 07:01:57

The area 积分积分的相关文章

HDU1071 The area 【积分】

The area Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7476    Accepted Submission(s): 5222 Problem Description Ignatius bought a land last week, but he didn't know the area of the land becau

[ACM] sdut 2877 angry_birds_again_and_again (简单数学积分)

angry_birds_again_and_again Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 The problems called "Angry Birds" and "Angry Birds Again and Again" has been solved by many teams in the series of contest in 2011 Multi-University

Matlab基础学习------------------函数的极值、积分问题Matlab实现

<span style="font-size:18px;">% 函数的积分问题Matlab实现 %% 函数极值点 % 1.一元函数的极小值点 % 实例:求f(x)=x^3-x^2-x+1在区间[-2,2]的极小值点 [email protected](x)x.^3-x.^2-x+1 x=fminbnd(f,-2,2) %使用fminbnd()函数求解一元函数的极小值点,参数分别为f(x)和区间短点 y=f(x) %极小值点对应的函数值 %结果 % f = % @(x)x.^

积分过期策略

策略:优先消耗上一年获取的积分,用户上一年获取的积分余额在本年度12月31号过期.例如:用户在2015年总共获取1000积分,在2016年12月31号这1000积分中还剩余100积分,那么这100积分就应该过期. 设计用户积分表: available_points: 用户当前可用积分 current_year: 当前年份 points_current_year:今年获取的积分总数 points_last_year:去年获取的积分总数 获取积分:points_current_year=points

混合云技术社区用户积分等级制度

混合云技术社区采用独立货币模式--混合云社区金币,混合云社区金币可在混合云社区礼品店换取精美小礼品,换取规则可进礼品店查看:http://bbs.51cto.com/cloud/index.php?m=gifts 混合云社区金币获取模式: 1. 对每个新加入的用户送200金币,每日签到10金币 2. 社区内发帖.传资源.写博文等可获得混合云社区专属金币,金币可在礼品店换取51CTO无忧币.下载豆.51CTO无忧币不能再本社区用,比如不能通过本社区礼品商店换取礼品. 操作 获得积分/刀币 说明 日

hdu 1071 The area 高斯消元求二次函数+辛普森积分

构造系数矩阵,高斯消元求解二次函数,然后两点式求直线函数,带入辛普森积分法无脑AC... #include<cstdio> #include<queue> #include<algorithm> #include<cstring> #include<vector> #include<cmath> using namespace std; struct node { double x,y; }p[4]; double g[10][10]

SPOJ CIRU The area of the union of circles ——Simpson积分

[题目分析] 圆的面积并. 直接Simpson积分,(但是有计算几何的解法,留着flag). simpson积分,如果圆出现了不连续的情况,是很容易出事情的.(脑补一下) 但是没有什么办法,本来就是一种取巧的做法,还能指望这暴力积分做什么. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include &l

基于Boost方法的人脸检测(1):整体思路

先推荐大家看着两篇: [2] Viola P, Jones M J. Robust Real-Time Face Detection[J]. International Journal of Computer Vision, 2004, 57(2):137-154. [3] http://www.cnblogs.com/ello/archive/2012/04/28/2475419.html [4] http://blog.csdn.net/xiaowei_cqu/article/details

数据挖掘中所需的概率论与数理统计知识

http://blog.csdn.net/v_july_v/article/details/8308762 数据挖掘中所需的概率论与数理统计知识 (关键词:微积分.概率分布.期望.方差.协方差.数理统计简史.大数定律.中心极限定理.正态分布) 导言:本文从微积分相关概念,梳理到概率论与数理统计中的相关知识,但本文之压轴戏在本文第4节(彻底颠覆以前读书时大学课本灌输给你的观念,一探正态分布之神秘芳踪,知晓其前后发明历史由来),相信,每一个学过概率论与数理统计的朋友都有必要了解数理统计学简史,因为,