标签:des style blog http color os strong io
Description
Input
Output
Sample Input
Sample Output
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 }
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ERKE/p/3889116.html