SPOJ CIRU The area of the union of circles ——Simpson积分
【题目分析】
圆的面积并。
直接Simpson积分,(但是有计算几何的解法,留着flag)。
simpson积分,如果圆出现了不连续的情况,是很容易出事情的。(脑补一下)
但是没有什么办法,本来就是一种取巧的做法,还能指望这暴力积分做什么。
【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> #include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 1005
#define eps 1e-6
#define db double
#define ll long long
#define ldb long double
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
} int n,cnt=0,tag[maxn],tot;
struct Circle{int x,y,r;}c[maxn];
struct Segment{db l,r;}a[maxn]; bool cmp(Segment x,Segment y)
{return x.l==y.l?x.r<y.r:x.l<y.l;} bool cmp1(Circle a,Circle b)
{return a.r<b.r;} db get(db x)
{
int cnt=0;
F(i,1,n) if (fabs(c[i].x-x)<=c[i].r-eps)
{
db tmp=sqrt(c[i].r*c[i].r-(x-c[i].x)*(x-c[i].x));
a[++cnt]=(Segment){c[i].y-tmp,c[i].y+tmp};
}
sort(a+1,a+cnt+1,cmp);
db h=-inf,ans=0;
F(i,1,cnt)
{
if (a[i].l>h) ans+=a[i].r-a[i].l,h=a[i].r;
else if (a[i].r>h) ans+=a[i].r-h,h=a[i].r;
}
return ans;
} db cal(db l,db r)
{
db mid=(l+r)/2,fl=get(l),fr=get(r),fm=get(mid);
return (r-l)/6*(fl+fr+4*fm);
} db simpson(db l,db r)
{
db mid=(l+r)/2,s1=cal(l,r),s2=cal(l,mid)+cal(mid,r);
if (fabs(s2-s1)<=eps) return s2;
else return simpson(l,mid)+simpson(mid,r);
} int main()
{
Finout();n=Getint();
F(i,1,n)
{
c[i].x=Getint();
c[i].y=Getint();
c[i].r=Getint();
}
sort(c+1,c+n+1,cmp1);
F(i,1,n-1) F(j,i+1,n)
{
if ((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[j].r-c[i].r)*(c[j].r-c[i].r))
{
tag[i]=1;
break;
}
}
F(i,1,n) if (!tag[i]) c[++tot]=c[i];
n=tot;
printf("%.3f\n",simpson(-2000.0,2000.0));
}
SPOJ CIRU The area of the union of circles ——Simpson积分的更多相关文章
- SPOJ CIRU - The area of the union of circles (圆的面积并)
CIRU - The area of the union of circles no tags You are given N circles and expected to calculate t ...
- SPOJ CIRU The area of the union of circles
You are given N circles and expected to calculate the area of the union of the circles ! Input The f ...
- SPOJ CIRU The area of the union of circles (计算几何)
题意:求 m 个圆的并的面积. 析:就是一个板子题,还有要注意圆的半径为0的情况. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024 ...
- 【题解】CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178]
[题解]CIRU - The area of the union of circles [SP8073] \ 圆的面积并 [Bzoj2178] 传送门: \(\text{CIRU - The area ...
- SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)
Description You are given N circles and expected to calculate the area of the union of the circles ! ...
- SPOJ 8073 The area of the union of circles (圆并入门)
Sphere Online Judge (SPOJ) - Problem CIRU [求圆并的若干种算法,圆并扩展算法]_AekdyCoin的空间_百度空间 参考AekdyCoin的圆并算法解释,根据 ...
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- SPOJ CIRU SPOJ VCIRCLE 圆的面积并问题
SPOJ VCIRCLE SPOJ CIRU 两道题都是给出若干圆 就面积并,数据规模和精度要求不同. 求圆面积并有两种常见的方法,一种是Simpson积分,另一种是几何法. 在这里给出几何方法. P ...
- SPOJ CIRU
SPOJ CIRU 题意 给出n个圆,求他们覆盖的面积. 解法 自适应Simpson,但需要将圆离散化一下,以保证我们查询的是一个连续的有圆的区间. 奇怪的是我没有离散化,样例都没有过,却把题给A了 ...
随机推荐
- log explorer使用的几个问题[转载]
1)对数据库做了完全 差异 和日志备份备份时选用了删除事务日志中不活动的条目再用Log explorer打试图看日志时提示No log recorders found that match the f ...
- MATLAB批量修改图片名称
申明:转载请注明出处. 设在“D:\UserDesktop\pic\”目录下有很多张格式为jpg照片,命名不规则,如图. 现在用MATLAB批量修改所有图片的命名格式,改为1.jpg,2.jpg,.. ...
- 删除.cpp文件
今天启动vc6.0后随手直接建了一个.cpp文件(没有建什么工程的),编译运行成功后,就把vc关了.后想把这个随手建的文件给删掉,却怎么也找不到这个文件,文件搜索或改变文件的属性也无法找到这个文件,即 ...
- Luogu P5352 Terrible Homework
神仙@TheLostWeak出的题,因为他最近没时间所以我先写一下sol(其实我也没什么时间) 作为一道简单的数据结构题想必大家都能看出必须用LCT维护信息吧 一个朴素的想法就是直接维护四种操作的值, ...
- 在tomcat中配置连接池
在tomcat的conf/Catalina/localhost目录下配置项目路径,tomcat启动是会直接根据配置去加载项目. 虽然配置就一句话,但经常忘,今天记下来. 如果你的项目成名是:mypro ...
- RedHat7搭建KVM虚拟机
RedHat7搭建KVM虚拟机 1. 宿主机安装RedHat7.3系统 1.1选择语言 中文.简体中文(中国) 1.2安装位置 1.2.1自定义分区,选择LVM,将分区空间全部分配给根 1.2.2禁用 ...
- SimpleWeather APP
参考 iOS 7 Best Practices; A Weather App Case Study: Part 1/2 iOS 7 Best Practices; A Weather App Case ...
- clover 显卡注入功能详细讲解
13 March 2014 GraphicsInjector功能源于变色龙,不过比变色龙更加灵活,定制性更加强大.Intel的显卡 GMA950, X3100, HD300, HD4000被证实可 ...
- JS原型链(二)--new运算符的原理
new运算符的原理: 第一步:创建一个空对象,该对象继承构造函数的原型对象 第二步:执行这个构造函数,并且把this指向该空对象 第三步:返回:如果构造函数执行后返回的结果是一个object类型,则返 ...
- 【NOIP2017提高A组冲刺11.6】拆网线
和syq大兄弟吐槽题目不小心yy出了正解.. 最优的选法就是选两个两个相互独立的,欸这不就是最大匹配吗?那多的企鹅就新加一条边呗?不够的就除以2上取整呗? 欸?AC了? 树也是一个二分图,最大匹配=最 ...