【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因此这种做法是一个坑....以后再填..

首先得知道如何求这些圆的并:

圆的面积并=每个圆没有被覆盖的弧(弦那里算起)的面积和+所有相交圆被覆盖弧所组成的多边形(由弦做边)

正确性自己画图.....

因此题目变为先求没有被覆盖的弧(直接离散圆周长为线,具体操作请看上上一题...),然后算出每个圆未被覆盖(就是覆盖弧的弦以外的)的面积,然后再用叉积求出多边形面积(原理就是多边形的面积可以通过加加减减得到...)

然后就完了

好题!

时间: 2024-08-01 08:04:58

【BZOJ】2178: 圆的面积并的相关文章

BZOJ 2178: 圆的面积并 [辛普森积分 区间并]

2178: 圆的面积并 Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1740  Solved: 450[Submit][Status][Discuss] Description 给出N个圆,求其面积并 Input 先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数 Output 面积并,保留三位小数 太可怕了!!!!!! 直接上辛普森积分 函数值就是x=..线上的区间并 区间并直接排序扫描就可以了

BZOJ 2178 圆的面积并 Simpson自适应公式

题目大意:给定n个圆,求面积并 直接暴力套用Simpson自适应公式就行了 对于每一个x值,求出F(x)的方法是求出所有圆在直线x=x(重了233)上的截取区间 然后求区间并 返回区间长度即是F值 这样正常写就过样例了 然后 WA了... 尼玛我样例都过了你跟我说WA? 下面是注意事项: 1.此题卡精度 EPS要设为1e-13 设为1e-12会WA 2.标程精度不够 不能用long double 否则会WA 3.这样会TLE 解决方法是预先将内含与其他圆的圆删掉 然后就能过了 这明显是卡数据啊-

BZOJ 2178 圆的面积并 Simpson积分

题意:链接 方法: Simpson积分 解析: 这题是有正解的=-= 不过Simpson积分可过. 首先 ∫rlf(x)=(r?l)(f(l)+f(r)+4f(mid))6 然后就强行递归搞就行了. 至于f(i)的值,在本题就是x=i这条直线与所有可以相交的圆的截线长的和. 这个的话用勾股定理求即可. 然后有一个方法 Simpson积分自适应法=-= 我们只需要强行套用公式,然后检验左半边的如上函数值加上右半边的如上函数值与我们强行套用公式得出来的值是否在精度范围允许内,如果在的话直接retur

bzoj 2178 圆的面积并【simpson积分】

直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段. 然而一定要去掉被其他圆完全覆盖的圆,否则会TLE #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> using namespace std; const double eps=1e-13; const int N=1005; int n,m; double mn=1e13,mx

BZOJ 2178 圆的面积并 ——Simpson积分

[题目分析] 史上最良心样例,史上最难调样例. Simpson积分硬上. 听说用long double 精度1e-10才能过. 但是double+1e-6居然过了. [代码] #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <map> #include <set> #include <queue> #incl

【BZOJ】【2178】圆的面积并

自适应辛普森积分 Orz Hzwer 辛普森真是个强大的东西……很多东西都能积= = 这题的正解看上去很鬼畜,至少我这种不会计算几何的渣渣是写不出来……(对圆的交点求图包,ans=凸包的面积+一堆弓形的面积,另外还有中空的情况……那种凸包怎么求啊喂!) 1 /************************************************************** 2 Problem: 2178 3 User: Tunix 4 Language: C++ 5 Result: A

POJ 2546 &amp; ZOJ 1597 Circular Area 两圆的面积交

Circular Area Time Limit: 2 Seconds      Memory Limit: 65536 KB Your task is to write a program, which, given two circles, calculates the area of their intersection with the accuracy of three digits after decimal point. Input In the single line of in

BZOJ 1845: [Cqoi2005] 三角形面积并 [计算几何 扫描线]

1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 1151  Solved: 313[Submit][Status][Discuss] Description 给出n个三角形,求它们并的面积. Input 第一行为n(N < = 100), 即三角形的个数 以下n行,每行6个整数x1, y1, x2, y2, x3, y3,代表三角形的顶点坐标.坐标均为不超过10 ^ 6的实数,输入数据保留1位小数 Out

java定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个findArea()方法返回圆的面积

需求如下:(1)定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个findArea()方法返回圆的面积. (2)定义一个类PassObject,在类中定义一个方法printAreas(),该方法的定义如下: public void printAreas(Cirlce c, int times) 在printAreas方法中打印输出1到time之间的每个整数半径值,以及对应的面积.例如,times为5,则输出半径1,2,3,4,5,以及对应的圆面积. 在main方法