心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
题目意思很简单,求抛物线和直线围成的区域的面积。
积分大牛都是0msAC的……不怎么会积分,于是直接龙贝格定积分求值。
以下是我的代码:
/*
 * Author:  lee1r
 * Created Time:  2011/8/23 18:19:49
 * File Name: hdu1071.cpp
 
*/
#include
<iostream>
#include
<sstream>
#include
<fstream>
#include
<vector>
#include
<list>
#include
<deque>
#include
<queue>
#include
<stack>
#include
<map>
#include
<set>
#include
<bitset>
#include
<algorithm>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<cctype>
#include
<cmath>
#include
<ctime>
#define L(x) ((x)<<1)
#define R(x) ((x)<<1|1)
#define Half(x) ((x)>>1)
#define Lowbit(x) ((x)&(-(x)))
using namespace std;
const int kInf(0x7f7f7f7f);
const double kEps(1e-8);
typedef unsigned 
int uint;
typedef 
long long int64;
typedef unsigned 
long long uint64;

bool scanf(int &num)
{
    
char in;
    
while((in=getchar())!=EOF && (in>'9' || in<'0'));
    
if(in==EOF) return false;
    num
=in-'0';
    
while(in=getchar(),in>='0' && in<='9') num*=10,num+=in-'0';
    
return true;
}

double A,B,C;

double f(double x)
{
    
return (A*x*x+B*x+C);
}

double Romberg(double a,double b,double eps)
{
    
#define MAX_N 1000
    
int min,tmp2;
    
double d,tmp4,R[2][MAX_N];
    
    
for(int i=0;i<MAX_N;i++)
        R[
0][i]=R[1][i]=.0;
    d
=b-a;
    min
=(int)(log(d*10.0)/log(2.0));
    R[
0][0]=0.5*d*(f(a)+f(b));
    tmp2
=1;
    
for(int i=2;i<MAX_N;i++)
    {
        R[
1][0]=.0;
        
for(int j=1;j<=tmp2;j++)
            R[
1][0]+=f(a+d*((double)j-0.5));
        R[
1][0]=(R[0][0]+d*R[1][0])*0.5;
        tmp4
=4.0;
        
for(int j=1;j<i;j++)
        {
            R[
1][j]=R[1][j-1]+(R[1][j-1]-R[0][j-1])/(tmp4-1.0);
            tmp4
*=4.0;
        }
        
if((fabs(R[1][i-1]-R[0][i-2])<eps) && (i>min))
            
return R[1][i-1];
        d
*=0.5;
        tmp2
*=2;
        
for(int j=0;j<i;j++)
            R[
0][j]=R[1][j];
    }
    
return R[1][MAX_N-1];
}

int main()
{
    #ifndef ONLINE_JUDGE
    
//freopen("data.in","r",stdin);
    #endif

    
int T;
    scanf(T);
    
while(T--)
    {
        
double x0,y0,x1,y1,x2,y2;
        scanf(
"%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);
        B
=(y2-y1-(x2*x2-x1*x1)*(y1-y0)/(x1*x1-x0*x0))/(x2-x1-(x2*x2-x1*x1)/(x1+x0));
        A
=(y1-y0-(x1-x0)*B)/(x1*x1-x0*x0);
        C
=y0-A*x0*x0-B*x0;
        B
-=(y2-y1)/(x2-x1);
        C
+=x1*(y2-y1)/(x2-x1)-y1;
        
        printf(
"%.2f\n",Romberg(x1,x2,kEps));
    }
    
    
return 0;
}
posted on 2011-08-23 18:56 lee1r 阅读(297) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:数学/数论

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理