题意:有一个长l宽w的矩形,左下角坐标是(0,0),现在有n条线段把这个矩形切割,保证每条线段的两个端点落在矩形不同的边上,把矩形分成了若干区域,现在有m个圆画进矩形,问圆覆盖了哪些区域,并把这些区域的面积排序输出。
题解:先要切割矩形,方法是每读入一条线段都拿去处理切割出的新的区域把原先的区域替换,最后可以得到一个区域的vector,然后判断圆和区域的情况:
1.如果圆没有公共点,可以是圆在某个区域内,或某些区域在圆内。这时需要判断多边形是否有顶点在圆内,或圆心是否在那个多边形内。
2.判断圆和每个区域的交点,如果是线段两个端点在圆上,就用线段中点判断是否在圆内。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
struct Point {
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
};
typedef Point Vector;
typedef vector<Point> Polygon;
struct Circle {
Point c;
double r;
Circle() {}
Circle(Point c, double r = 0): c(c), r(r) {}
Point point(double a) {
return Point(c.x + cos(a) * r, c.y + sin(a) * c.y);
}
};
double Sqr(double x) {
return x * x;
}
double dcmp(double x) {
if (fabs(x) < eps)
return 0;
return x < 0 ? -1 : 1;
}
Vector operator + (const Point& A, const Point& B) {
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (const Point& A, const Point& B) {
return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (const Point& A, double a) {
return Vector(A.x * a, A.y * a);
}
Vector operator / (const Point& A, double a) {
return Vector(A.x / a, A.y / a);
}
double Cross(const Vector& A, const Vector& B) {
return A.x * B.y - A.y * B.x;
}
double Dot(const Vector&