SPOJ 8073 The area of the union of circles (圆并入门)
Sphere Online Judge (SPOJ) - Problem CIRU
【求圆并的若干种算法,圆并扩展算法】_AekdyCoin的空间_百度空间
参考AekdyCoin的圆并算法解释,根据理解写出的代码。圆并这么多题中,最基础一题。
操作如下:
(1)对一个圆,获得所有与其他圆的交点作为时间戳。
a.如果这个圆不被其他任何圆覆盖,这个圆直接保留。
b.如果Case中有两个完全重合的圆,可以保留标号小(或大)的圆,也只保留这一个。
(2)每经过一个时间戳就对计数器加减,如果计数器从0变1,加上这段圆弧和对应的三角形。
(3)所有这样的圆独立计算,最后求出的面积累加即可。
代码如下(1y):
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm> using namespace std; const double PI = acos(-1.0);
const double EPS = 1e-;
inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
template<class T> T sqr(T x) { return x * x;}
typedef pair<double, double> Point;
#define x first
#define y second
Point operator + (Point a, Point b) { return Point(a.x + b.x, a.y + b.y);}
Point operator - (Point a, Point b) { return Point(a.x - b.x, a.y - b.y);}
Point operator * (Point a, double p) { return Point(a.x * p, a.y * p);}
Point operator / (Point a, double p) { return Point(a.x / p, a.y / p);} inline double cross(Point a, Point b) { return a.x * b.y - a.y * b.x;}
inline double dot(Point a, Point b) { return a.x * b.x + a.y * b.y;}
inline double angle(Point a) { return atan2(a.y, a.x);}
inline double veclen(Point a) { return sqrt(dot(a, a));} struct Circle {
Point c;
double r;
Circle() {}
Circle(Point c, double r) : c(c), r(r) {}
Point point(double p) { return Point(c.x + r * cos(p), c.y + r * sin(p));}
void get() { scanf("%lf%lf%lf", &c.x, &c.y, &r);}
} ; bool ccint(Circle a, Circle b, double &a1, double &a2) { // ips for Circle-a (anti-clockwise p1->p2)
double d = veclen(a.c - b.c);
double r1 = a.r, r2 = b.r;
if (sgn(d - r1 - r2) >= ) return ;
if (sgn(fabs(r1 - r2) - d) >= ) return ;
double da = acos((sqr(d) + sqr(r1) - sqr(r2)) / ( * d * r1));
double ang = angle(b.c - a.c);
a1 = ang - da, a2 = ang + da;
return ;
} const int N = ;
Circle cir[N]; inline double gettri(Point o, Point a, Point b) { return cross(a - o, b - o) / ;}
inline double getarc(Circle o, double a, double b) { return (b - a) * sqr(o.r) / - gettri(o.c, o.point(a), o.point(b));} typedef pair<double, int> Event;
Event ev[N << ]; bool inside(int a, int n) {
double d, r1, r2;
for (int i = ; i < n; i++) {
if (i == a) continue;
d = veclen(cir[i].c - cir[a].c);
r1 = cir[i].r, r2 = cir[a].r;
if (sgn(r1 - r2) == && sgn(fabs(r1 - r2) - d) == ) {
if (i > a) return ;
continue;
}
if (sgn(r1 - r2) >= && sgn(fabs(r1 - r2) - d) >= ) return ;
}
return ;
} double getarea(int a, int n) {
if (inside(a, n)) return ;
Circle &c = cir[a];
double ret = ;
double a1, a2;
Point p1, p2;
int tt = ;
for (int i = ; i < n; i++) {
if (i == a) continue;
if (ccint(c, cir[i], a1, a2)) {
if (a2 > PI) ev[tt++] = Event(a1, ), ev[tt++] = Event(PI, -), ev[tt++] = Event(-PI, ), ev[tt++] = Event(a2 - * PI, -);
else if (a1 < -PI) ev[tt++] = Event(a1 + * PI, ), ev[tt++] = Event(PI, -), ev[tt++] = Event(-PI, ), ev[tt++] = Event(a2, -);
else ev[tt++] = Event(a1, ), ev[tt++] = Event(a2, -);
}
}
if (tt == ) return PI * sqr(c.r);
sort(ev, ev + tt);
int cnt = ;
double last = -PI;
for (int i = ; i < tt; i++) {
double cur = ev[i].x;
if (ev[i].y == && cnt == ) ret += getarc(c, last, cur) + cross(c.point(last), c.point(cur)) / ;
cnt += ev[i].y;
last = cur;
}
ret += getarc(c, last, PI) + cross(c.point(last), c.point(PI)) / ;
return ret;
} double work(int n) {
double ret = ;
for (int i = ; i < n; i++) ret += getarea(i, n);
return ret;
} int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = ; i < n; i++) cir[i].get();
printf("%.3f\n", work(n));
}
return ;
}
——written by Lyon
SPOJ 8073 The area of the union of circles (圆并入门)的更多相关文章
- 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 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 ...
- SPOJ CIRU The area of the union of circles ——Simpson积分
[题目分析] 圆的面积并. 直接Simpson积分,(但是有计算几何的解法,留着flag). simpson积分,如果圆出现了不连续的情况,是很容易出事情的.(脑补一下) 但是没有什么办法,本来就是一 ...
- 【题解】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-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 ...
- POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]
Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21734 Accepted: 8179 Descrip ...
随机推荐
- 20190719-FirstZero
这也许也是一个成就吧? First Zero 考试 第一次 爆0 好了好了. T1 你永远不知道你在想什么. 我仿佛想出一个$\Theta(NM\log^2 N)$的$dfs$??? 蒟蒻原地爆炸 T ...
- Codeforces Round #573 (Div. 2)
A:Tokitsukaze and Enhancement 当时看错条件了..以为A>C>B>D.就胡写了判断条件. #include<bits/stdc++.h> us ...
- git图形化
在windows下安装git中文版客户端并连接gitlab 转载自:https://blog.whsir.com/post-1801.html 下载git Windows客户端 git客户端下载地址: ...
- Redis分布式锁的实现及注意事项
一.前言 分布式锁一般有三种实现方式: 1. 数据库乐观锁: 2. 基于Redis的分布式锁: 3. 基于ZooKeeper的分布式锁. 本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上 ...
- linux挂载点 和 文件系统$ mount$ cat /etc/fstab$ vgs$ pvs$ lvs$ df -h$ lsof +D / /* beware not to kill your box */
$ mount$ cat /etc/fstab$ vgs$ pvs$ lvs$ df -h$ lsof +D / /* beware not to kill your box */ 一共挂载了多少文件 ...
- GYM 101350 F. Monkeying Around
F. Monkeying Around time limit per test 2.0 s memory limit per test 256 MB input standard input outp ...
- idea 创建properties配置文件
[转载]原文链接:https://blog.csdn.net/caoPengFlying/article/details/78660379 我们在j2ee当中,连接数据库的时候经常会用到propert ...
- web前端学习(二)html学习笔记部分(5)--拖放元素、canvas画布使用
1.2.11 拖放 1.2.11.1 html拖放 1.2.11.2 html拖放本次资源 showOjb(一个对象)展示一下一个对象的信息. 1.2.12 html画布(canvas) 标 ...
- python通过http(multipart/form-data)上传文件的方法
之前写过一篇博客,说的如何python如何通过http下载文件,今天写一篇博客来介绍如下,python如何通过request库实现上传文件 这里主要是解决multipart/form-data这种格式 ...
- css 垂直+水平居中
垂直+水平居中是一个老生常谈的问题了,现在就固定高度和不固定高度两种情况去讨论 1.父盒子固定高度[定位] 实现1: father-box: position:relative child-box:p ...