bzoj 2178 圆的面积并【simpson积分】
直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段。
然而一定要去掉被其他圆完全覆盖的圆,否则会TLE
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps=1e-13;
const int N=1005;
int n,m;
double mn=1e13,mx=-1e13;
bool fl[N];
struct cir
{
double x,y,r;
double operator < (const cir &a) const
{
return r<a.r;
}
}c[N];
struct qwe
{
double l,r;
qwe(double L=0,double R=0)
{
l=L,r=R;
}
bool operator < (const qwe &a) const
{
return l<a.l;
}
}a[N];
int cmp(double x)
{
if(x<=eps&&x>=-eps)
return 0;
return x>0?1:-1;
}
double f(double x)
{
int cnt=0;
for(int i=1;i<=n;i++)
{
double dis=fabs(c[i].x-x);
if(cmp(dis-c[i].r)<0)
{
double len=sqrt(c[i].r*c[i].r-dis*dis);
a[++cnt]=qwe(c[i].y-len,c[i].y+len);
}
}
if(!cnt)
return 0;
sort(a+1,a+1+cnt);
double l=a[1].l,r=a[1].r,ans=0;
for(int i=2;i<=cnt;i++)
{
if(cmp(a[i].l-r)<=0)
r=max(r,a[i].r);
else
ans+=r-l,l=a[i].l,r=a[i].r;
}
ans+=r-l;
return ans;
}
double sps(double l,double r,double now,double fl,double fr,double fm)
{
double mid=(l+r)/2,ffl=f((l+mid)/2),ffr=f((mid+r)/2),p=(fl+fm+ffl*4)*(mid-l)/6,q=(fm+fr+ffr*4)*(r-mid)/6;
if(cmp(now-p-q)==0)
return now;
else
return sps(l,mid,p,fl,fm,ffl)+sps(mid,r,q,fm,fr,ffr);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
mn=min(mn,c[i].x-c[i].r),mx=max(mx,c[i].x+c[i].r);
}//cout<<"OK"<<endl;
sort(c+1,c+1+n);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(cmp(sqrt((c[i].x-c[j].x)*(c[i].x-c[j].x)+(c[i].y-c[j].y)*(c[i].y-c[j].y))+c[i].r-c[j].r)<=0)
{
fl[i]=1;
break;
}
for(int i=1;i<=n;i++)
if(!fl[i])
c[++m]=c[i];
n=m;
double fl=f(mn),fr=f(mx),fm=f((mn+mx)/2);
printf("%.3lf\n",sps(mn,mx,(fl+4*fm+fr)*(mx-mn)/6,fl,fr,fm));
return 0;
}
bzoj 2178 圆的面积并【simpson积分】的更多相关文章
- BZOJ 2178 圆的面积并 ——Simpson积分
[题目分析] 史上最良心样例,史上最难调样例. Simpson积分硬上. 听说用long double 精度1e-10才能过. 但是double+1e-6居然过了. [代码] #include < ...
- BZOJ 2178: 圆的面积并 [辛普森积分 区间并]
2178: 圆的面积并 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1740 Solved: 450[Submit][Status][Discus ...
- bzoj 2178 圆的面积并 —— 辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...
- bzoj 2178 圆的面积并——辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...
- BZOJ 2178: 圆的面积并 (辛普森积分)
code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...
- [BZOJ 2178] 圆的面积并 【Simpson积分】
题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13 2)要去掉被其他圆包含的圆. ...
- 【BZOJ】2178: 圆的面积并
http://www.lydsy.com/JudgeOnline/problem.php?id=2178 题意:给出n<=1000个圆,求这些圆的面积并 #include <cstdio& ...
- BZOJ 1845: [Cqoi2005] 三角形面积并 (辛普森积分)
大力辛普森积分 精度什么的搞了我好久- 学到了Simpson的一个trick 深度开11,eps开1e-4.跑的比有些扫描线还快- CODE #include <bits/stdc++.h> ...
- BZOJ 1502 月下柠檬树(simpson积分)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1502 题意:给出如下一棵分层的树,给出每层的高度和每个面的半径.光线是平行的,与地面夹角 ...
随机推荐
- equals() 和 hashCode()
equals() 和 hashCode()这两个方法在java.lang.Object中,所有的类都可以继承这两个方法: 但是,这两个方法在Object类中的实现一般没什么用,所以你通常需要自己重载这 ...
- BZOJ——4195: [Noi2015]程序自动分析
http://www.lydsy.com/JudgeOnline/problem.php?id=4195 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: ...
- 109.Convert sorted list to BST
/* * 109.Convert sorted list to BST * 2016.12.24 by Mingyang * 这里的问题是对于一个链表我们是不能常量时间访问它的中间元素的. * 这时候 ...
- eclipse提速02 - eclipse.ini优化
给eclipse执行jvm.它可以让你使用自己的jdk,而不是系统环境变量所指定的jdk -vm /path/to/your/java 使用最新的jdk来运行eclipse.使用最新的jdk要好很多. ...
- AE的Annotation学习摘记
http://xg-357.blog.163.com/blog/static/36263124201151763512894/ IFeatureWorkspaceAnno pFWSAnno = (IF ...
- 【Nginx】Hello world程序
模块如何在运行中生效 配置文件中的location块决定了匹配某种URL的请求将会由相应的HTTP模块处理,因此,运行时HTTP框架会在接收完毕HTTP请求的头部后,将请求的URL与配置文件中的所有l ...
- es5~es6
1.用箭头函数减少代码(相信你在Vue已经看到了) ES5: function greetings (name) { return 'hello ' + name } ES6: const greet ...
- java 配置时遇到的问题及解决办法
1. 最近JDK更新很频繁,以至于我安装时版本太多,选择也会出现问题 首先,确定你选择的是32位版本还是64位版本(貌似64位系统下也可以安装32位的JDK), 这个相当重要,因为这个会影响到ecli ...
- POST 请求静态文件 响应405
使用post方式请求js.html这样的静态文件一般的web服务器都会返回405 Method Not Allowed. 我测试用的web服务器用的是IIS(windows10+IIS10),理论上来 ...
- 【bzoj1965】[Ahoi2005]SHUFFLE 洗牌
x*2^m==l (mod n+1)x=(n/2+1)^m*l mod n+1 #include<algorithm> #include<iostream> #include& ...