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. MongoDB工具简要说明

    [mongodb@hadoop1 bin]$ pwd /usr/local/mongodb/bin [mongodb@hadoop1 bin]$ ls -l total 207696 -rwxr-xr ...

  2. 10 款提高开发效率的 jQuery/CSS3 组件

    前端开发是一项十分繁琐而又耗体力的工作,如何更有效率的开发我们的应用,很多人会选择适当地使用一些jQuery插件.今天就要给大家分享10款可以提高开发效率的jQuery/CSS3组件.部分插件可以下载 ...

  3. Android--ViewPager的无限轮播

    ViewPage_RadioButton实现带小圆点的无限轮播,效果还能凑合着用. 1.在ViewPage的监听里面这样处理 @Override public void onPageSelected( ...

  4. Android开发遇到的异常及解决办法

    Android开发遇到的错误及解决方法1. Unable to resolve target 'android-7' 解决方案: 修改工程目录下的default.properties文件里的内容tar ...

  5. Linux Centos 6.6搭建SFTP服务器

    Linux Centos 6.6搭建SFTP服务器 在Centos 6.6环境使用系统自带的internal-sftp搭建SFTP服务器. 打开命令终端窗口,按以下步骤操作. 0.查看openssh的 ...

  6. OO之工厂模式

    以下为工厂模式的详解,包括简单工厂,普通工厂模式,抽象工厂. 引子: 假设有一个交通工具公司,生产自行车,汽车,飞机等,现要销售该公司的产品,要怎么设计呢? 在交通工具商店中加一个if else判断如 ...

  7. 卷积神经网络CNN介绍:结构框架,源码理解【转】

    1. 卷积神经网络结构 卷积神经网络是一个多层的神经网络,每层都是一个变换(映射),常用卷积convention变换和pooling池化变换,每种变换都是对输入数据的一种处理,是输入特征的另一种特征表 ...

  8. android开发连接wifi addNetwork 返回-1

    如下代码:(注释掉的是会返回-1的代码,未注释的是能够正常连接wifi的代码) // public WifiConfiguration CreateWifiInfo(String SSID, Stri ...

  9. 【Implement strStr() 】cpp

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  10. SSIS 控制流和数据流(转)

    理解控制流和数据流的一个入口是看他们如何运行的.一个控制流任务是一个最小的执行单位,它的运行结果有成功,失 败,和完成,在运行它的下一个任务之前必须得到这些结果.在数据流任务中,转换时最基本的元素.一 ...