题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1502

题解:

simpson积分求面积,s = (f(a)+f(b)+4*f(c))/6*Δx ,c=(a+b)/2。

题中的树投影下来是一些圆和相邻圆的公切线组成的一个封闭图形,并且上下对称,所以可以只求上半部分。

simpson求面积时,若f(x)代价很大,要尽量减少其的重复调用。其次尽量优化f(x)函数的计算。

写完后还要自己出极限随机数据,将eps调到能接受的最大值。

 #include <cstdio>
#include <cmath>
#include <iostream>
#define maxn 510
#define eps 1e-6
using namespace std; int sg( double x ) {
return (x>-eps)-(x<eps);
}
struct Vector {
double x, y;
Vector(){}
Vector( double x, double y ) : x(x), y(y) {}
Vector operator+( Vector b ) { return Vector(x+b.x,y+b.y); }
Vector operator-( Vector b ) { return Vector(x-b.x,y-b.y); }
Vector operator*( double b ) { return Vector(x*b,y*b); }
double len() {
return sqrt( x*x+y*y );
}
};
typedef Vector Point; struct Line {
Point A, B;
double k, b;
double lf, rg;
Line(){}
Line( Point A, Point B ):A(A),B(B) {
if( A.x>B.x ) swap(A,B);
lf = A.x;
rg = B.x;
k = (B.y-A.y)/(B.x-A.x);
b = A.y-A.x*k;
}
inline bool in( double x ) {
return sg(x-lf)>= && sg(rg-x)>=;
}
inline double f( double x ) { return k*x+b; }
void out() {
printf( "(%lf,%lf) (%lf,%lf) \n", A.x, A.y, B.x, B.y );
}
};
struct Circle {
Point C;
double r;
double lf, rg;
Circle(){}
void make() {
lf = C.x-r;
rg = C.x+r;
}
inline bool in( double x ) {
return sg(x-lf)>= && sg(rg-x)>=;
}
inline double f( double x ) {
return sqrt( r*r-(C.x-x)*(C.x-x) );
}
void out() {
printf( "(%lf,%lf) r=%lf\n", C.x, C.y, r );
}
}; int n;
double alpha;
Line lines[maxn];
Circle cirs[maxn]; Line cir_tang( Circle & a, Circle & b ) {
double ang = acos( (a.r-b.r)/(b.C.x-a.C.x) );
Point A = a.C + Vector(cos(ang),sin(ang))*a.r;
Point B = b.C + Vector(cos(ang),sin(ang))*b.r;
return Line(A,B);
} double F( double x ) {
double y = -1.0;
for( int i=; i<=n; i++ ) {
if( cirs[i].lf-eps<=x && x<=cirs[i].rg+eps )
y = max( y, cirs[i].f(x) );
if( i&& lines[i].lf-eps<=x && x<=lines[i].rg+eps )
y = max( y, lines[i].f(x) );
}
return y;
}
inline double simpson( double a, double b, double fa, double fb, double fc ) {
return (fa+*fc+fb)*(b-a)/;
}
double adapt( double a, double b, double c, double fa, double fb, double fc ) {
double d = (a+c)/, e = (c+b)/;
double fd = F(d), fe = F(e);
double sa = simpson(a,c,fa,fc,fd);
double sb = simpson(c,b,fc,fb,fe);
double ss = simpson(a,b,fa,fb,fc);
if( fabs(sa+sb-ss)<*eps ) return sa+sb;
return adapt(a,c,d,fa,fc,fd)+adapt(c,b,e,fc,fb,fe);
} int main() {
scanf( "%d%lf", &n, &alpha );
double k = /tan(alpha);
double hsum = 0.0, h;
double lf=1e200, rg=-1e200;
for( int i=; i<=n; i++ ) {
scanf( "%lf", &h );
hsum += h;
cirs[i].C.x = hsum*k;
cirs[i].C.y = 0.0;
}
for( int i=; i<n; i++ ) {
scanf( "%lf", &cirs[i].r );
cirs[i].make();
lf = min( lf, cirs[i].lf );
rg = max( rg, cirs[i].rg );
}
cirs[n].r = 0.0;
rg = max( rg, cirs[n].C.x );
for( int i=; i<=n; i++ )
lines[i] = cir_tang( cirs[i-], cirs[i] );
printf( "%.2lf\n", adapt(lf,rg,(lf+rg)/,F(lf),F(rg),F((lf+rg)/) )* );
}

bzoj1502 simpson求面积的更多相关文章

  1. poj 3348--Cows(凸包求面积)

    链接:http://poj.org/problem?id=3348 Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:  ...

  2. P - Atlantis - hdu1542(求面积)

    题意:rt 求面积......不计算重复面积(废话..)hdu1255 的弱化版,应该先做这道题在做那道题的. ******************************************** ...

  3. 编写一个矩形类,私有数据成员为矩形的长( len)和宽(wid),wid设置为0,有参构造函数设置和的值,另外,类还包括矩形的周长、求面积、取矩形的长度、取矩形的长度、取矩形的宽度、修改矩形的长度和宽度为对应的形参值等公用方法。

    class Rectangle { private double len, wid; public Rectangle()//求矩形周长 { len = 0; wid = 0; } public Re ...

  4. HDU - 1255 覆盖的面积 (线段树求面积交)

    https://cn.vjudge.net/problem/HDU-1255 题意 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 分析 求面积并的题:https://www.cnbl ...

  5. 覆盖的面积 HDU - 1255(扫描线求面积交)

    题意: 就是扫描线求面积交 解析: 参考求面积并.... 就是把down的判断条件改了一下..由w > 0 改为 w > 1 同时要讨论一下 == 1 时  的情况, 所以就要用到一个临时 ...

  6. hdu1542 Atlantis 线段树--扫描线求面积并

    There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...

  7. 两条线段求交点+叉积求面积 poj 1408

    题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...

  8. 牛客训练二:处女座的签到题(STL+精度+三角形求面积公式)

    题目链接:传送门 知识点: (1)三个点,三角形求面积公式 (2)精度问题: double 15-16位(参考文章) float 6-7位 long long 约20位 int 约10位 unsign ...

  9. Herding(hdu4709)三点运用行列式求面积

    Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

随机推荐

  1. PHP对象3: public / private / protected

    <?php /* public 可继承, 内外可访问 private 不可, 只内部访问 protected 可继承, 只内部 */ class A{ protected $name; priv ...

  2. onvif客户端

    前言 做开发有8年时间了,ffmpeg和onvif与我是特别有缘的了(说着玩的,我更认为是因为他们确实强大^_^). ffmpeg在毕业设计时就有用到,5年后做windows.linux播放库时又有用 ...

  3. SQLite3数据库的操作

    数据库的操作 我们在这个项目中使用的是SQLITE3数据库软件. 通过使用SQLITE3进行创建数据库,创建表,插入记录,查询记录,更新记录,关闭数据库等操作来实现将相应的数据存入数据库中. 打开数据 ...

  4. eWebEditor复制粘贴图片时过滤域名

    1.找到form.js 路径:plugins/frame/scripts/form.js 这个方法: 2.替换这个方法 /** * 处理参数 */ Form.prototype.processReqP ...

  5. HttpURLConnection传json

    private static String sendToWangTing(DataRow dataRow) throws IOException{ String ip = Configuration. ...

  6. oracle日期格式转换 to_date()

    与date操作关系最大的就是两个转换函数:to_date(),to_char()       to_date() 作用将字符类型按一定格式转化为日期类型:       具体用法:to_date(''2 ...

  7. Nginx源码分析-ngx_module_s结构体

    该结构体是整个Nginx模块化架构最基本的数据结构体.它描述了Nginx程序中一个模块应该包括的基本属性,在tengine/src/core/ngx_conf_file.h中定义了该结构体 struc ...

  8. 安装mysql驱动之 mysqlclient 出现的报错处理(ubuntu16.04)

    首先 更新软件! sudo apt-get update 然后尝试安装mysqlclient,报错 后执行下面的步骤 安装mysql驱动之 mysqlclient 出现的报错信息处理 报错1: OSE ...

  9. 不需要打密码的sudo方法

    Linux下频繁输入sudo很麻烦.如果你的账户已经是sudoer了,那么编辑/etc/sudoers,将 %sudo ALL=(ALL:ALL) ALL 修改为: %sudo ALL=(ALL) N ...

  10. 关于Android不同系统版本的市场占比情况详解

    一,google官方统计的不同Android版本市场的占比强开 google统计的数据情况 这个是google官方对于不同版本的市场占比情况.这个是针对全世界所有的Android手机占比情况. 二,友 ...