http://acm.hdu.edu.cn/showproblem.php?pid=1071
The area
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7751 Accepted Submission(s): 5442
Note: The point P1 in the picture is the vertex of the parabola.
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).
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
33.33 40.69HintFor float may be not accurate enough, please use double instead of float.数学题,设抛物线的方程为y=a*x*x+b*x+c,直线的方程为y=k*x+d。此题不考虑抛物线开口向左和向右的情况,下面就是用已知三点求抛物线的a,b,c,已知两点求直线的k,d。代码如下。#include<stdio.h> #include<string.h> #define NUM 3 struct Point { double x; double y; }num[NUM+5]; int main() { int T,i; double sum,sum_1,sum_2,a,b,c,d,k; scanf("%d",&T); while(T--) { for(i=0;i<NUM;i++) scanf("%lf %lf",&num[i].x,&num[i].y); a=(num[1].y-num[0].y)/(num[1].x*num[1].x-num[0].x*num[0].x+2*num[0].x*num[0].x-2*num[0].x*num[1].x); b=-2*a*num[0].x; c=num[0].y-a*num[0].x*num[0].x-b*num[0].x; //printf("%lf %lf %lf\n",a,b,c); k=(num[2].y-num[1].y)/(num[2].x-num[1].x); d=num[1].y-(num[2].y-num[1].y)*num[1].x/(num[2].x-num[1].x); //printf("%lf %lf\n",k,d); sum_2=(1.0/3.0)*a*(num[2].x)*(num[2].x)*(num[2].x)+(1.0/2.0)*(b-k)*(num[2].x)*(num[2].x)+(c-d)*num[2].x; sum_1=(1.0/3.0)*a*(num[1].x)*(num[1].x)*(num[1].x)+(1.0/2.0)*(b-k)*(num[1].x)*(num[1].x)+(c-d)*num[1].x; sum=sum_2-sum_1; printf("%.2lf\n",sum); } return 0; }
2万+



被折叠的 条评论
为什么被折叠?



