simpson
使用二次函数拟合复杂的连续函数求积分
对于(l,r)拟合的积分为(r-l)*(f(l)+4*f((l+r)/2)+f(r))/6
___________________________
BZOJ2178
#include <cstdio>
#include <cmath>
#include <algorithm>
#define LDB double
using namespace std; const LDB eps=1e-;
LDB ans=; struct data{
LDB x,y,r,va;
}a[],tmp[]; int st,en,n,del[]; int mycomp (const data&a,const data&b){
return(a.va<b.va);
} LDB dis(data a,data b){
return(sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)));
} LDB getf(LDB xx){
int cnt=;
for (int i=st;i<=en;i++)
if (fabs(a[i].x-xx)<a[i].r-eps){
tmp[++cnt]=a[i];tmp[cnt].va=a[i].y-sqrt(a[i].r*a[i].r-(a[i].x-xx)*(a[i].x-xx));
}
sort(tmp+,tmp+cnt+,mycomp); LDB ret=;int po;
for (int i=;i<=cnt;i=po+){
po=i;LDB last=*tmp[i].y-tmp[i].va;
while (po<cnt&&tmp[po+].va<last){
po++;
last=max(last,*tmp[po].y-tmp[po].va);
}
ret+=(last-tmp[i].va);
}
return(ret);
} LDB cal(LDB l,LDB r,LDB fl,LDB fmid,LDB fr){
return((r-l)*(fl+*fmid+fr)/);
} void simpson(LDB l,LDB r,LDB fl,LDB fmid,LDB fr){
LDB mid=(l+r)/;
LDB mid1=(l+mid)/,mid2=(mid+r)/;
LDB f1=getf(mid1),f2=getf(mid2);
LDB num1=cal(l,r,fl,fmid,fr);
LDB num2=cal(l,mid,fl,f1,fmid)+cal(mid,r,fmid,f2,fr);
if (fabs(num1-num2)<eps) {ans+=num1;return;}
simpson(l,mid,fl,f1,fmid);simpson(mid,r,fmid,f2,fr);
} void work(){
int po;LDB last;
for (int i=;i<=n;i=po+){
po=i,last=a[i].x+a[i].r;
while (po<n&&a[po+].x-a[po+].r<last+eps){
po++;
last=max(last,a[po].x+a[po].r);
}
st=i;en=po;
simpson(a[i].x-a[i].r,last,getf(a[i].x-a[i].r),getf((a[i].x-a[i].r+last)/),getf(last));
}
} int main(){
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%lf%lf%lf",&tmp[i].x,&tmp[i].y,&tmp[i].r);
for (int i=;i<=n;i++)
for (int j=;j<=n;j++)
if (i!=j)
if (dis(tmp[i],tmp[j])<tmp[j].r-tmp[i].r) {del[i]=;break;}
int cnt=;
for (int i=;i<=n;i++)
if (!del[i]) a[++cnt]=tmp[i],a[cnt].va=a[cnt].x-a[cnt].r;
n=cnt;
sort(a+,a+n+,mycomp); work();
printf("%.3lf\n",ans);
}
simpson的更多相关文章
- 【BZOJ-1502】月下柠檬树 计算几何 + 自适应Simpson积分
1502: [NOI2005]月下柠檬树 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: 562[Submit][Status] ...
- 农场阳光 (simpson)
计算若干个圆与一个矩形的面积并 simpson公式 ans = ( f[l] + f[r] + 4 * f[mid] ) * (r-l) / 6 uses math; type arr=record ...
- BZOJ 1502 月下柠檬树(simpson积分)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1502 题意:给出如下一棵分层的树,给出每层的高度和每个面的半径.光线是平行的,与地面夹角 ...
- UVa 10465 Homer Simpson (枚举)
10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- 10465 - Homer Simpson 贪心
Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Home ...
- [BZOJ 2178] 圆的面积并 【Simpson积分】
题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13 2)要去掉被其他圆包含的圆. ...
- [BZOJ 1502] [NOI2005] 月下柠檬树 【Simpson积分】
题目链接: BZOJ - 1502 题目分析 这是我做的第一道 Simpson 积分的题目.Simpson 积分是一种用 (fl + 4*fmid + fr) / 6 * (r - l) 来拟合 fl ...
- UVA 10465 Homer Simpson(dp + 完全背包)
Problem C: Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Homer Simpson, a very smart guy, ...
- hdu 1724 Ellipse simpson积分
/* hdu 1724 Ellipse simpson积分 求椭圆的部分面积 simpson积分法 http://zh.wikipedia.org/zh-tw/%E8%BE%9B%E6%99%AE%E ...
随机推荐
- 2.ASP.NET MVC 中使用Crystal Report水晶报表
上一篇,介绍了怎么导出Excel文件,这篇文章介绍在ASP.NET MVC中使用水晶报表. 项目源码下载:https://github.com/caofangsheng93/CrystalReport ...
- 『.NET Core CLI工具文档』(十四)dotnet-install 脚本参考
说明:本文是个人翻译文章,由于个人水平有限,有不对的地方请大家帮忙更正. 原文:dotnet-install scripts reference 翻译:dotnet-install 脚本参考 名称 d ...
- C#开发微信门户及应用(31)--微信语义理解接口的实现和处理
微信语义理解接口提供从用户自然语言输入到结构化解析的技术实现,使用先进的自然语言处理技术给开发者提供一站式的语义解析方案.该平台覆盖多个垂直领域的语义场景,部分领域还可以支持取得最终的展示结果.开发者 ...
- 锐捷linux客户端常用命令(主要用来连接校园网或公司局域网)
锐捷访问校园网,.sh脚本文件rjsu*.sh-u 用户名-P 密码-S 参数1保存密码参数0不保存密码 其实: 直接使用md5认证方式输入用户名密码并且配置好ip之后,重新打开网卡即可有一定 ...
- JAVA 入门第二章 (面对对象)
本渣渣鸽了一个月终于有时间更新.因为有c++基础,学起来这章还是比较简单的,本章我觉得是程序猿质变课程,理解面向对象的思想,掌握面向对象的基本原则以及 Java 面向对象编程基本实现原理,熟练使用封装 ...
- 图表插件Charts.js的使用
Charts.js的介绍自行百度 首先下载Charts.js,官网:http://chartjs.cn/ charts.js 托管在了github上,下载下来后加解压出src中的文件即可.其中有cha ...
- centos6.5下使用yum完美搭建LNMP环境(php5.6) 无脑安装
准备工作 配置防火墙,开启80端口.3306端口删除原有的 iptables , 添加合适的配置 rm -rf /etc/sysconfig/iptables vi /etc/sysconfig/ip ...
- tomcat项目中文乱码问题解决方法
在部署tomcat项目时经常会遇到中文乱码问题,解决的方法可参考以下步骤. 1.更改Tomcat安装目录下的conf\server.xml,指定浏览器的编码格式为"utf-8"格式 ...
- Google C++单元测试框架GoogleTest---AdvancedGuide(译文)下
因为AdvancedGuide文档太长,分上下两部分,本文档接googletest--AdvancedGuide(译文)上:Google C++单元测试框架GoogleTest---AdvancedG ...
- Intellij idea 和android studio 代码给混淆
Intellij idea 和android studio 代码给混淆 一.指令说明-optimizationpasses 5 # 指定代码的压缩级别 -dontusemixedcaseclassna ...