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. STL之迭代器

    容器支持的迭代器类型  STL Container  Type of Iterators Supported   vector  random access iterators 元素严格有序(类似数组 ...

  2. JTable的DefaultModel方法getValueAt(a,row)

    行和列都是从0开始索引的,而且不包括netbeans生成的表格头,而是从数据开始,否则就会报错

  3. 多线程异步加载图片async_pictures

    异步加载图片 目标:在表格中异步加载网络图片 目的: 模拟 SDWebImage 基本功能实现 理解 SDWebImage 的底层实现机制 SDWebImage 是非常著名的网络图片处理框架,目前国内 ...

  4. .net 动态编译解决考勤计算问题

    由于公司实施SAP HR项目,但是SAP HR对考勤功能真的太弱化了,直接从考勤机上读取的原始打卡记录不能直接传输到HR系统里面,因为SAP HR不能识别那些多余的打卡记录,而且必须把打卡记录进行成组 ...

  5. 基于socket的客户端和服务端聊天机器人

    服务端代码如下: using System;using System.Net;using System.Net.Sockets;using System.Text;using System.Threa ...

  6. Android--调用系统的DownLoadManager去下载文件

    代码里面有详细的注释: /** * 该方法是调用了系统的下载管理器 */ public void downLoadApk(Context context,String url){ /** * 在这里返 ...

  7. hdu 1053 Entropy

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1053 Entropy Description An entropy encoder is a data ...

  8. Go语言参数中的三个点是干什么的

    Go语言函数中有三个点...表示为可变参数,可以接受任意个数的参数. 示例代码: package main import "fmt" func Greeting(prefix st ...

  9. UIView的创建与内存管理

    学习过程中遇到一些问题,现在记录下来,以后忘记以便翻看. 创建工程的步骤: xcode的ARC改为MRC .h文件中的strong改为retain .m文件中加入dealloc方法 .m文件中_win ...

  10. Content Template & DataTemplate 区别

    转一篇很好的博客: http://www.cnblogs.com/lzhp/p/3250786.html 介绍 listbox 的 Template.ItemsPanel.ItemContainerS ...