Simpson法相当好用啊!神奇的骗分算法!

 /**************************************************************
Problem: 1502
User: zhuohan123
Language: C++
Result: Accepted
Time:228 ms
Memory:1312 kb
****************************************************************/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1e-,pi=3.141592653589793238;
int n;
struct point
{
double x,y;
point(){}
point(double X,double Y){x=X,y=Y;}
};
struct line
{
point s,e;
line(){}
line(point S,point E){s=S,e=E;}
double y(double x){return (e.y*s.x-e.x*s.y-e.y*x+s.y*x)/(s.x-e.x);}
}l[];int lnum;
struct circle{double x,r;}c[];
double h[];
double f(double x)
{
double s=;
for(int i=;i<n;i++)
{
if(abs(x-c[i].x)+eps<c[i].r)s=max(s,sqrt(c[i].r*c[i].r-(x-c[i].x)*(x-c[i].x)));
if(l[i].s.x<x+eps&&l[i].e.x>x-eps)s=max(s,l[i].y(x));
}
return s*;
}
const double dev=1e-;
inline double simpson(double l,double r,double fl,double fm,double fr){return (fl+*fm+fr)/*(r-l);}
double integral(double l,double fl,double m,double fm,double r,double fr,double pre)
{
double lm=(l+m)/,rm=(m+r)/,flm=f(lm),frm=f(rm);
double intl=simpson(l,m,fl,flm,fm),intr=simpson(m,r,fm,frm,fr);
return abs(intl+intr-pre)<dev?intl+intr:integral(l,fl,lm,flm,m,fm,intl)+integral(m,fm,rm,frm,r,fr,intr);
}
int main(int argc, char *argv[])
{
double alp;scanf("%d%lf",&n,&alp);n++;
for(int i=;i<=n;i++)scanf("%lf",&h[i]);
for(int i=;i<n;i++)scanf("%lf",&c[i].r);c[n].r=;
double s=1e10,e=-1e10;
for(int i=;i<=n;i++)
{
h[i]+=h[i-];
c[i].x=h[i]/tan(alp);
s=min(s,c[i].x-c[i].r);
e=max(e,c[i].x+c[i].r);
}
for(int i=;i<n;i++)
{
double dx=c[i+].x-c[i].x,dr=c[i].r-c[i+].r;
if(abs(dx)<abs(dr)+eps)continue ;
l[++lnum]=line(point(c[i].x+c[i].r/dx*dr,sqrt(c[i].r*c[i].r-(c[i].r/dx*dr)*(c[i].r/dx*dr)))
,point(c[i+].x+c[i+].r/dx*dr,sqrt(c[i+].r*c[i+].r-(c[i+].r/dx*dr)*(c[i+].r/dx*dr))));
}
double m=(s+e)/,fm=f(m);
printf("%.2lf\n",integral(s,,m,fm,e,,simpson(s,e,,fm,)));
return ;
}

BZOJ1502: [NOI2005]月下柠檬树的更多相关文章

  1. [日常摸鱼]bzoj1502[NOI2005]月下柠檬树-简单几何+Simpson法

    关于自适应Simpson法的介绍可以去看我的另一篇blog http://www.lydsy.com/JudgeOnline/problem.php?id=1502 题意:空间里圆心在同一直线上且底面 ...

  2. 【BZOJ1502】[NOI2005]月下柠檬树 Simpson积分

    [BZOJ1502][NOI2005]月下柠檬树 Description 李哲非常非常喜欢柠檬树,特别是在静静的夜晚,当天空中有一弯明月温柔地照亮地面上的景物时,他必会悠闲地坐在他亲手植下的那棵柠檬树 ...

  3. BZOJ 1502: [NOI2005]月下柠檬树 [辛普森积分 解析几何 圆]

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1070  Solved: 596[Submit][Status] ...

  4. 【BZOJ-1502】月下柠檬树 计算几何 + 自适应Simpson积分

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1017  Solved: 562[Submit][Status] ...

  5. [NOI2005]月下柠檬树[计算几何(simpson)]

    1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1169  Solved: 626[Submit][Status] ...

  6. [NOI2005]月下柠檬树

    题意 F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ ModifyUser  autoint Logout 捐赠本站 Probl ...

  7. 5.21 省选模拟赛 luogu P4207 [NOI2005]月下柠檬树 解析几何 自适应辛普森积分法

    LINK:月下柠檬树 之前感觉这道题很鬼畜 实际上 也就想到辛普森积分后就很好做了. 辛普森积分法的式子不再赘述 网上多的是.值得一提的是 这道题利用辛普森积分法的话就是一个解析几何的问题 而并非计算 ...

  8. 【bzoj1502】[NOI2005]月下柠檬树 自适应Simpson积分

    题目描述 李哲非常非常喜欢柠檬树,特别是在静静的夜晚,当天空中有一弯明月温柔地照亮地面上的景物时,他必会悠闲地坐在他亲手植下的那棵柠檬树旁,独自思索着人生的哲理.李哲是一个喜爱思考的孩子,当他看到在月 ...

  9. BZOJ1502:[NOI2005]月下柠檬树——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1502 https://www.luogu.org/problemnew/show/P4207 李哲 ...

随机推荐

  1. 安装wampserver出现“The Program can't start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem”

    问题描述: 今天安装wampserver的时候出现"The Program can't start because MSVCR110.dll is missing from your com ...

  2. Android触摸屏配置调试

    前几天搞乐蛙时,进入后是鼠标模式,好坑爹的模式有木有~~ 但是大蛋给出了解决方法,我不怕不怕啦~让我们向大牛致敬!!! 首先输入Command查看你的input配置~ adb shell dumpsy ...

  3. UVA 100 The 3*n+1 problem

      UVA 100 The 3*n+1 problem. 解题思路:对给定的边界m,n(m<n&&0<m,n<1 000 000);求X(m-1<X<n+ ...

  4. [C#] 记-TinyMapper使用

    What is TinyMapper TinyMapper - a tiny and quick object mapper for .Net. The main advantage is perfo ...

  5. “后PC”时代来临

    “后PC”时代来临 数年前,喜达屋酒店及度假村国际集团将总部搬迁至美国康涅狄格州斯坦福,这也让公司首席执行官Frits van Paasschen有机会“除尘换新”. 那么,Frits van Paa ...

  6. Object-c 语法 - NSObject常用方法和反射

    NSObject常用方法 - (BOOL)isKindOfClass:(Class)aClass //判断是否为aClass或者aClass的子类的实例,aClass可以通过[类名 class]获取 ...

  7. firebreath 在谷歌和火狐浏览器下的调试 以及打包

    在寻找插件开发资料的过程中找到了一个开发浏览器插件的开源项目——firebreath firebreath的安装以及测试我就不再叙述了,可以参考大神的文章 . http://www.blogjava. ...

  8. licens 问题 Error (292028): Specified license is not valid for this machine

    集成网卡调试的时候坏了,造成了quartus 不可以用,MAC地址不对应了... 应该怎么解决呢??.

  9. How to check if NSString begins with a certain character

    How to check if NSString begins with a certain character How do you check if an NSString begins with ...

  10. 巧用 .NET 中的「合并运算符」获得 URL 中的参数

    获取 URL 中的 GET 参数,无论用什么语言开发网站,几乎是必须会用到的代码.但获取 URL 参数经常需要注意一点就是要先判断是否有这个参数存在,如果存在则取出,如果不存在则用另一个值.这个运算称 ...