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了 ...
随机推荐
- COGS 2566. [51nod 1129] 字符串最大值
★★★ 输入文件:string_maxval.in 输出文件:string_maxval.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 一个字符串的前缀是指包 ...
- 如何找到SAP Cloud for Customer标准培训和认证方面的信息
有一些朋友询问我如何在SAP官网上找到和SAP Cloud for Customer相关的标准培训信息,我这里把步骤写出来: 登录SAP官网https://training.sap.com 输入和Cl ...
- 什么是Java Marker Interface(标记接口)
先看看什么是标记接口?标记接口有时也叫标签接口(Tag interface),即接口不包含任何方法.在Java里很容易找到标记接口的例子,比如JDK里的Serializable接口就是一个标记接口. ...
- 数据库_8_SQL基本操作——数据操作
SQL基本操作——数据操作 一.新增数据(两种方案) 方案1: 给全表字段插入数据,不需要指定字段列表,要求数据的值出现的顺序必须与表中设计的字段出现的顺序一致,凡是非数值数据,都需要使用引号(建议是 ...
- Hopfield 网络(上)
讲的什么 这部分主要对 Hopfield 网络作一大概的介绍.写了其模型结构.能量函数和网络的动作方式.主要参考了网上搜到的一些相关 PPT. 概述 早在 1982 年,Hopfield 发表的文 ...
- KeyValuePair的使用
Dictionary<string, string> dc = new Dictionary<string, string>(); 前台页面: <div id=" ...
- 题解 P1189 SEARCH
(传送门)[https://www.luogu.org/problemnew/show/P1189] 先反省一波:我以后再也不用getchar()+scanf了(日常爆零) 算是比较裸的搜索吧,在下用 ...
- 【线段树】uoj#228. 基础数据结构练习题
get到了标记永久化 sylvia 是一个热爱学习的女孩子,今天她想要学习数据结构技巧. 在看了一些博客学了一些姿势后,她想要找一些数据结构题来练练手.于是她的好朋友九条可怜酱给她出了一道题. 给出一 ...
- [LUOGU] 1090 合并果子
题目描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和.可 ...
- 玩转ApplicationContextAware
当一个类实现了这个接口之后,这个类就可以方便地获得 ApplicationContext 中的所有bean.换句话说,就是这个类可以直接获取Spring配置文件中,所有有引用到的bean对象.结合工厂 ...