SPOJ CIRU The area of the union of circles (计算几何)
题意:求 m 个圆的并的面积。
析:就是一个板子题,还有要注意圆的半径为0的情况。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<double, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 10;
const int mod = 1e6;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int dcmp(double x){
if(fabs(x) < eps) return 0;
if(x > 0) return 1;
return -1;
}
double sqr(double x){ return x * x; } struct Point{
double x, y;
Point(){ }
Point(double a, double b) : x(a), y(b) { }
void input(){
scanf("%lf %lf", &x, &y);
}
friend Point operator + (const Point &a, const Point &b){
return Point(a.x + b.x, a.y + b.y);
}
friend Point operator - (const Point &a, const Point &b){
return Point(a.x - b.x, a.y - b.y);
}
friend bool operator == (const Point &a, const Point &b){
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
friend Point operator * (const Point &a, const double &b){
return Point(a.x * b, a.y * b);
}
friend Point operator * (const double &b, const Point &a){
return Point(a.x * b, a.y * b);
}
friend Point operator / (const Point &a, const double &b){
return Point(a.x / b, a.y / b);
}
double norm(){
return sqrt(sqr(x) + sqr(y));
}
};
double cross(const Point &a, const Point &b){
return a.x * b.y - a.y * b.x;
}
struct Circle{
Point p;
double r;
bool operator < (const Circle &o) const{
if(dcmp(r-o.r) != 0) return dcmp(r-o.r) == -1;
if(dcmp(p.x-o.p.x) != 0) return dcmp(p.x - o.p.x) == -1;
return dcmp(p.y - o.p.y) == -1;
}
bool operator == (const Circle &o) const{
return dcmp(r - o.r) == 0 && dcmp(p.x - o.p.x) == 0 && dcmp(p.y - o.p.y) == 0;
}
};
Point rotate(const Point &p, double cost, double sint){
double x = p.x, y = p.y;
return Point(x*cost - y*sint, x*sint + y*cost);
} pair<Point, Point> crossPoint(Point ap, double ar, Point bp, double br){
double d = (ap - bp).norm();
double cost = (ar*ar + d*d - br*br) / (2.0*ar*d);
double sint = sqrt(1.0 - cost*cost);
Point v = (bp - ap) / (bp - ap).norm() * ar;
return make_pair(ap+rotate(v, cost, -sint), ap+rotate(v, cost, sint));
} pair<Point, Point> crossPoint(const Circle &a, const Circle &b){
return crossPoint(a.p, a.r, b.p, b.r);
}
Circle c[maxn], tc[maxn];
#include<complex>
struct Node{
Point p;
double a;
int d;
Node(const Point &pp, double aa, int dd) : p(pp), a(aa), d(dd) { }
bool operator < (const Node &o) const{
return a < o.a;
}
};
double arg(Point p){
return arg(complex<double> (p.x, p.y));
} double solve(){
sort(tc, tc + m);
m = unique(tc, tc + m) - tc;
n = 0;
for(int i = m-1; i >= 0; --i){
bool ok = true;
for(int j = i+1; j < m; ++j){
double d = (tc[i].p - tc[j].p).norm();
if(dcmp(d - abs(tc[i].r - tc[j].r)) <= 0){
ok = false; break;
}
}
if(ok) c[n++] = tc[i];
}
double ans = 0.0;
for(int i = 0; i < n; ++i){
vector<Node> event;
Point boundary = c[i].p + Point(-c[i].r, 0);
event.push_back(Node(boundary, -PI, 0));
event.push_back(Node(boundary, PI, 0));
for(int j = 0; j < n; ++j){
if(i == j) continue;
double d = (c[i].p - c[j].p).norm();
if(dcmp(d - (c[i].r + c[j].r)) < 0){
pair<Point, Point> ret = crossPoint(c[i], c[j]);
double x = arg(ret.first - c[i].p);
double y = arg(ret.second - c[i].p);
if(dcmp(x - y) > 0){
event.push_back(Node(ret.first, x, 1));
event.push_back(Node(boundary, PI, -1));
event.push_back(Node(boundary, -PI, 1));
event.push_back(Node(ret.second, y, -1));
}
else{
event.push_back(Node(ret.first, x, 1));
event.push_back(Node(ret.second, y, -1));
}
}
}
sort(event.begin(), event.end());
int sum = event[0].d;
for(int j = 1; j < event.size(); ++j){
if(sum == 0){
ans += cross(event[j-1].p, event[j].p) / 2.0;
double x = event[j-1].a;
double y = event[j].a;
double area = c[i].r * c[i].r * (y-x) / 2.0;
Point v1 = event[j-1].p - c[i].p;
Point v2 = event[j].p - c[i].p;
area -= cross(v1, v2) / 2.0;
ans += area;
}
sum += event[j].d;
}
}
return ans;
} int main(){
while(scanf("%d", &n) == 1){
m = 0;
for(int i = 0; i < n; ++i){
tc[m].p.input();
scanf("%lf", &tc[m].r);
if(dcmp(tc[m].r) <= 0) continue;
++m;
}
printf("%.3f\n", solve());
}
return 0;
}
SPOJ CIRU The area of the union of 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 ——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 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了 ...
随机推荐
- adb tcp 调试
su setprop service.adb.tcp.port 5555 stop adbd start adbd
- 关于移动端文字无法垂直居中(或line-height不起作用)的问题的解决方案(网摘)
最近开发移动端APP,发现安卓端对于文字垂直居中的问题兼容性不好,网上也搜了很多方法,但是都比较麻烦,自己摸索出来了最终的解决方案: 1.首先在html头部把我们常用的lang="en&qu ...
- BZOJ 2818 Gcd 线性欧拉
题意:链接 方法:线性欧拉 解析: 首先列一下表达式 gcd(x,y)=z(z是素数而且x,y<=n). 然后我们能够得到什么呢? gcd(x/z,y/z)=1; 最好还是令y>=x 则能 ...
- 实记处理mongodb的NUMA问题
一次在启动mongodb的过程中,出现过NUMA这个问题, mongodb日志显示如下: WARNING: You are running on a NUMA machine. We suggest ...
- sql无限级树型查询
表结构如下: 表数据如下: 一提到无限级,很容易想到递归,使用sql 的CET语法如下 with menu(Id,Name,ParentId,Level) as ( select Id,Name,Pa ...
- php 面向对象的三大要素(封装、继承、多态)以及重写(override)和重载(overload)的举例说明
PHP是一种HTML内嵌式的,用来制作动态网页的服务器端的脚本语言.其特点是:开发周期短,稳定安全,简单易学,免费开源,良好的跨平台特性.PHP是一种面向对象的程序设计语言,目前已成为全球最受欢迎的五 ...
- 安装DotNetCore.1.0.1-VS2015Tools.Preview2.0.3引发的血案
1.下载了一个开源项目,是用netcore开发的 2.VS2015打不开解决方案 3.于是安装DotNetCore.1.0.1-VS2015Tools.Preview2.0.3 4.安装成功,项目顺利 ...
- 配置tomcat,实现域名访问项目
首先,配置tomcat端口号为80,配置方法:配置tomcat,访问端口改为80 然后,配置访问项目时候,不用项目名,配置方法:配置tomcat,使访问项目时候无项目名 最后,配置tomcat的ser ...
- 最简单的Windows程序
准备研究一下vmp 保护,从一个最简单的Windows程序入手似乎是个不错的想法. 如何才最简单呢,仅仅有一个MessageBox 调用好了. 弹出消息.退出,哦也,够简单吧. 祭出法器VC2010. ...
- Javascript - ERR_CONTENT_LENGTH_MISMATCH
不知道做了什么,有两天没有跑vue项目啦,今天突然出现加载脚本的时候出现 ERR_CONTENT_LENGTH_MISMATCH这个错误, 所以我去搜索了一下 找到如下答案 http://stac ...