杭电1071-The area

问题描述:

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.

问题分析:

注意:
          已知抛物线与直线相交两点和抛物线顶点,顶点P1(-b/(2a), (4ac-b^2)/4a)。
          抛物线方程:y=ax^2+bx+c;
          直线方程:y=kx+h;
          已知p1,p2,p3可以求出a,b,c,k,h
          y1=ax1^2+bx1+c
          y2=ax2^2+bx2+c
          y1-y2=(x1-x2)(a(x1+x2)+b)
          又x1=-b/2a,
          所以a=(y2-y1)/(x2-x1)^2
          面积用积分公式化简为:
          S=a/3*(x3^3–x2^3)+(b-k)/2*(x3^2–x2^2)+(c-h)*(x3-x2);

AC代码:

#include <cstdlib>
#include <iostream>
#include<iomanip>
using namespace std;

int main(int argc, char *argv[])
{
    double x1,x2,x3,y1,y2,y3,area;
    double a,b,c,k,h;
    int n;
    cin>>n;
    while(n--)
    {
       cin>>x1>>y1;
       cin>>x2>>y2;
       cin>>x3>>y3;
       a=(y2-y1)/((x2-x1)*(x2-x1));
       b=-2*a*x1;
       c=y1-a*x1*x1-b*x1;
       k=(y3-y2)/(x3-x2);
       h=y3-k*x3;
       area=a/3*(x3*x3*x3-x2*x2*x2)+(b-k)/2*(x3*x3-x2*x2)+(c-h)*(x3-x2);
       cout<<fixed<<setprecision(2)<<area<<endl;
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}

时间: 2024-11-15 01:28:22

杭电1071-The area的相关文章

杭电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>

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

杭电dp题集,附链接

Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋); 正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q[i].v)  其中,f[j]表示抢j块大洋的最大的逃脱概率,条件是f[j-q[i].money]可达,也就是

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

hdu 1016 Prime Ring Problem DFS解法 纪念我在杭电的第一百题

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29577    Accepted Submission(s): 13188 Problem Description A ring is compose of n circles as shown in diagram. Put natural num

一个人的旅行 HDU杭电2066【dijkstra算法】

http://acm.hdu.edu.cn/showproblem.php?pid=2066 Problem Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景--草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯粹看雪景,去巴黎喝咖啡写信,去北京探望孟姜女--眼看寒假就快到了,这么一大段时间,可不

杭电1162--Eddy&#39;s picture(Prim()算法)

Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8070    Accepted Submission(s): 4084 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to b

杭电1276--士兵队列训练问题

士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4605    Accepted Submission(s): 2148 Problem Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行