标签:others ora turn txt memory display hdu eof contain
Ellipse
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1977 Accepted Submission(s): 832Problem DescriptionMath is important!! Many students failed in 2+2’s mathematical test, so let‘s AC this problem to mourn for our lost youth..
Look this sample picture:
A ellipses in the plane and center in point O. the L,R lines will be vertical through the X-axis. The problem is calculating the blue intersection area. But calculating the intersection area is dull, so I have turn to you, a talent of programmer. Your task is tell me the result of calculations.(defined PI=3.14159265 , The area of an ellipse A=PI*a*b )
InputInput may contain multiple test cases. The first line is a positive integer N, denoting the number of test cases below. One case One line. The line will consist of a pair of integers a and b, denoting the ellipse equation , A pair of integers l and r, mean the L is (l, 0) and R is (r, 0). (-a <= l <= r <= a).
OutputFor each case, output one line containing a float, the area of the intersection, accurate to three decimals after the decimal point.
Sample Input2 2 1 -2 2 2 1 0 2
Sample Output6.283 3.142
Author威士忌
Source
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1724
题目大意:
求椭圆被x=l,x=r两条线所围区域面积。
题目思路:
【自适应Simpson积分】
首先易得上半部分面积积分公式为sqrt(b2(1-x2/a2))
接下来就是套用自适应Simpson积分即可。eps一开始设为1e-4就行。
一道模板题。
1 /**************************************************** 2 3 Author : Coolxxx 4 Copyright 2017 by Coolxxx. All rights reserved. 5 BLOG : http://blog.csdn.net/u010568270 6 7 ****************************************************/ 8 #include<bits/stdc++.h> 9 #pragma comment(linker,"/STACK:1024000000,1024000000") 10 #define abs(a) ((a)>0?(a):(-(a))) 11 #define lowbit(a) (a&(-a)) 12 #define sqr(a) ((a)*(a)) 13 #define mem(a,b) memset(a,b,sizeof(a)) 14 const double eps=1e-8; 15 const int J=10000; 16 const int mod=1000000007; 17 const int MAX=0x7f7f7f7f; 18 const double PI=3.14159265358979323; 19 const int N=104; 20 using namespace std; 21 typedef long long LL; 22 double anss; 23 LL aans; 24 int cas,cass; 25 int n,m,lll,ans; 26 double a,b; 27 double F(double x)//原函数f(x) 28 { 29 return sqrt(b*b*(1-x*x/(a*a))); 30 } 31 double simpson(double a,double b)//求simpson公式S(a,b) 32 { 33 double mid=(a+b)/2; 34 return (b-a)/6*(F(a)+4*F(mid)+F(b)); 35 } 36 double simpson(double l,double r,double eps,double A)//自适应simpson积分过程 37 { 38 double mid=(l+r)/2; 39 double L=simpson(l,mid); 40 double R=simpson(mid,r); 41 if(abs(L+R-A)<=15*eps)return L+R+(L+R-A)/15.0;//eps为精度需求 42 return simpson(l,mid,eps/2,L)+simpson(mid,r,eps/2,R); 43 } 44 double simpson(double l,double r,double eps)//自适应simpson积分 45 { 46 return simpson(l,r,eps,simpson(l,r)); 47 } 48 int main() 49 { 50 #ifndef ONLINE_JUDGE 51 // freopen("1.txt","r",stdin); 52 // freopen("2.txt","w",stdout); 53 #endif 54 int i,j,k; 55 double x,y,z; 56 // for(scanf("%d",&cass);cass;cass--) 57 for(scanf("%d",&cas),cass=1;cass<=cas;cass++) 58 // while(~scanf("%s",s)) 59 // while(~scanf("%d",&n)) 60 { 61 scanf("%lf%lf%lf%lf",&a,&b,&x,&y); 62 printf("%.3lf\n",simpson(x,y,1e-4)*2); 63 } 64 return 0; 65 } 66 /* 67 // 68 69 // 70 */
HDU 1724 Ellipse 【自适应Simpson积分】
标签:others ora turn txt memory display hdu eof contain
原文地址:http://www.cnblogs.com/Coolxxx/p/6666943.html