【BZOJ】2178: 圆的面积并
http://www.lydsy.com/JudgeOnline/problem.php?id=2178
题意:给出n<=1000个圆,求这些圆的面积并
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <sstream>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline int getint() { static int r, k; r=0,k=1; static char c; c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const double eps=1e-6, PI=acos(-1);
int dcmp(double x) { return abs(x)<eps?0:(x<0?-1:1); }
double sqr(double x) { return x*x; }
struct iP { double x, y; iP(double _x=0, double _y=0) : x(_x), y(_y) {} };
double dis(iP &a, iP &b) { return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y)); }
struct iC {
iP p; double r;
iP getP(double d) { return iP(p.x+cos(d)*r, p.y+sin(d)*r); }
double areaH(double d) { return (d-sin(d))/2*sqr(r); }
};
double angle(iP &a, iP &b) {
static double x, y;
x=b.x-a.x; y=b.y-a.y;
return atan2(y, x);
}
void CCi(iC &a, iC &b, double &ang1, double &ang2) {
static double ang, d, R, r, da;
d=dis(a.p, b.p); //dbg(d);
ang=angle(a.p, b.p);
R=a.r; r=b.r; //dbg((sqr(R)+sqr(d)-sqr(r))/2/R/d);
da=acos((sqr(R)+sqr(d)-sqr(r))/2/R/d);
ang1=ang-da;
ang2=ang+da;
} const int N=1105;
iC a[N];
int n, cnt;
bool nok[N];
struct dat { double pos; int k; }b[N*5];
bool cmp(const dat &a, const dat &b) { return a.pos<b.pos; } int main() {
read(n);
for1(i, 1, n) scanf("%lf%lf%lf", &a[i].p.x, &a[i].p.y, &a[i].r);
for1(i, 1, n) for1(j, 1, n) if(!nok[j] && i!=j) {
double d=dis(a[i].p, a[j].p);
if(dcmp(a[j].r-a[i].r-d)>=0) { nok[i]=1; break; }
}
double ang1, ang2, PI2=PI*2, ans=0;
int sum=0;
iP A, B;
for1(i, 1, n) if(!nok[i]) {
cnt=0;
for1(j, 1, n) if(i!=j && !nok[j]) {
if(dcmp(dis(a[i].p, a[j].p)-a[i].r-a[j].r)>=0) continue;
CCi(a[i], a[j], ang1, ang2);
if(dcmp(ang1)<0) ang1+=PI2;
if(dcmp(ang2)<0) ang2+=PI2;
if(dcmp(ang1-ang2)>0) {
++cnt; b[cnt].pos=0; b[cnt].k=1;
++cnt; b[cnt].pos=ang2; b[cnt].k=-1;
++cnt; b[cnt].pos=ang1; b[cnt].k=1;
++cnt; b[cnt].pos=PI2; b[cnt].k=-1;
}
else {
++cnt; b[cnt].pos=ang1; b[cnt].k=1;
++cnt; b[cnt].pos=ang2; b[cnt].k=-1;
}
}
++cnt; b[cnt].pos=0; b[cnt].k=0;
++cnt; b[cnt].pos=PI2; b[cnt].k=0;
sort(b+1, b+1+cnt, cmp);
sum=0;
for1(j, 1, cnt-1) {
sum+=b[j].k;
if(!sum) {
ans+=a[i].areaH(b[j+1].pos-b[j].pos);
A=a[i].getP(b[j].pos);
B=a[i].getP(b[j+1].pos);
ans+=(A.x*B.y-A.y*B.x)/2;
}
}
}
printf("%.3f\n", ans);
return 0;
}
这题坑了我3h啊啊啊啊啊.....................................................我就一sb...
这题有多种解法,什么是辛普森积分我不知道QAQ因此这种做法是一个坑....以后再填..
首先得知道如何求这些圆的并:
圆的面积并=每个圆没有被覆盖的弧(弦那里算起)的面积和+所有相交圆被覆盖弧所组成的多边形(由弦做边)
正确性自己画图.....
因此题目变为先求没有被覆盖的弧(直接离散圆周长为线,具体操作请看上上一题...),然后算出每个圆未被覆盖(就是覆盖弧的弦以外的)的面积,然后再用叉积求出多边形面积(原理就是多边形的面积可以通过加加减减得到...)
然后就完了
好题!
【BZOJ】2178: 圆的面积并的更多相关文章
- BZOJ 2178: 圆的面积并 [辛普森积分 区间并]
2178: 圆的面积并 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1740 Solved: 450[Submit][Status][Discus ...
- [BZOJ 2178] 圆的面积并 【Simpson积分】
题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13 2)要去掉被其他圆包含的圆. ...
- bzoj 2178 圆的面积并 —— 辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...
- bzoj 2178 圆的面积并——辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...
- bzoj 2178 圆的面积并【simpson积分】
直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段. 然而一定要去掉被其他圆完全覆盖的圆,否则会TLE #include<iostream> #incl ...
- BZOJ 2178 圆的面积并 ——Simpson积分
[题目分析] 史上最良心样例,史上最难调样例. Simpson积分硬上. 听说用long double 精度1e-10才能过. 但是double+1e-6居然过了. [代码] #include < ...
- BZOJ 2178: 圆的面积并 (辛普森积分)
code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...
- 【BZOJ】【2178】圆的面积并
自适应辛普森积分 Orz Hzwer 辛普森真是个强大的东西……很多东西都能积= = 这题的正解看上去很鬼畜,至少我这种不会计算几何的渣渣是写不出来……(对圆的交点求图包,ans=凸包的面积+一堆弓形 ...
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
随机推荐
- CentOS 初始化时的分区
/ ext3 8189 固定大小 空 swap 509 固定大小 /boot ext3 100 固定大小 /home ...
- QEMU 使用的镜像文件:qcow2 与 raw
qcow2 的基本原理 qcow2 镜像格式是 QEMU 模拟器支持的一种磁盘镜像.它也是可以用一个文件的形式来表示一块固定大小的块设备磁盘.与普通的 raw 格式的镜像相比,有以下特性: 更小的空间 ...
- Selenium webdriver 学习总结-元素定位
Selenium webdriver 学习总结-元素定位 webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要 ...
- 对Java中字符串的进一步理解
字符串在程序开发中无处不在,也是用户交互所涉及到最频繁的数据类型,那么字符串不仅仅就是我们简单的理解的String str = "abc";一起来更加深入的看一下 在Java中,字 ...
- codeforces B.Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/363/B 题目意思:给定整数n和k,需要从n个数中找出连续的k个数之和最小,输出这连续的k个数中的第一个数 ...
- Java问题排查工具箱[转载]
转载自:http://hellojava.info/?p=517 作者:阿里毕玄 问题排查除了最重要的解决思路和逻辑推导能力外,工具也是不可缺少的一部分,一个好用的工具可以事半功倍,甚至在某些情况下会 ...
- win8系统使用Administrator用户 命令行
windows键+X,再按A键进入管理员模式的命令提示符 输入命令:net user administrator /active:yes 然后注销,即可使用管理员账户登录
- Myeclipse 安装svn插件
安装subclipse, SVN插件1.从官网下载site-1.8.22.zip文件 访问不了可点我网盘2.从中解压出features与 plugins文件夹,复制到MyEclipse\MyEcl ...
- 引水入城(codevs 1066)
题目描述 Description 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政 区划十分特殊,刚好构成一个N行M列的矩形,如上图所示,其中每个格子都代表一座城 市,每座 ...
- 设计模式学习之建造者模式(Builder,创建型模式)(6)
假如我们需要建造一个房子,并且我们也不知道如何去建造房子,所以就去找别人帮我们造房子 第一步: 新建一个房子类House,里面有房子该有的属性,我们去找房子建造者接口HouseBuilder,我们要建 ...