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了 ...
随机推荐
- Objective-C Runtime Reference
This document describes the OS X Objective-C 2.0 runtime library support functions and data structur ...
- hihoCoder #1068 : RMQ-ST算法(模板)
AC G++ 826ms 146MB 思路: 时间复杂度O(nlogn). //#include <bits/stdc++.h> #include <iostream> #in ...
- jquery 不支持$.browser
if (!$.browser) { $.browser = { mozilla : /firefox/.test(navigator.userAgent.toLowerCase()), webkit ...
- Ubuntu14.04 32位安装Youcompleteme
前一段时间在ubuntu16.04 64位上安装了vim插件Youcompleteme,花了两三天才弄好.今天在ubuntu14.04 32位上安装同样的插件,才知道之前所做的安装原来是多么的简单.今 ...
- UVa 12219 Common Subexpression Elimination (stl,模拟,实现)
一般来说,把一颗子树离散成一个int,把一个结点的字符离散成一个int会方便处理 直接map离散.当然一个结点最多只有4个小写字母,也可以直接编码成一个27进制的整数,舍掉0,为了区分0和0000. ...
- ios push Payload
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotifi ...
- Java学习之初识线程
“身之主宰便是心,心之所发便是意,意之本体便是知,意之所在便是物 --摘自阳明先生语录” 1.概念 在说线程之前我们先了解关于进程的一些知识,什么是进程? 程序一旦运行就是一个独立的进程,以windo ...
- 理解 React,但不理解 Redux,该如何通俗易懂的理解 Redux?(转)
作者:Wang Namelos 链接:https://www.zhihu.com/question/41312576/answer/90782136来源:知乎 解答这个问题并不困难:唯一的要求是你熟悉 ...
- JS中鼠标左右键以及中键的事件
在三维场景中有时候需要判断鼠标的事件,除了使用的click事件,只有鼠标左键有效,而右键无效.而对于onmousedown.onmouseup的时候鼠标的事件左键/右键有效.详细请看w3c上的资料. ...
- shell脚本,打印九九乘法表。
[root@localhost ~]# .sh #!/bin/bash #计算九九乘法表 ` do ` do [ $j -le $i ] && echo -n "$i*$j= ...