Codeforces614C Peter and Snow Blower
题意:各一个点,一个多边形,多边形绕着这个点转,问转过的面积是多少
题解:可以发现转过的面积就是一个圆环,这里的多边形可能是凹多边形,环外的半径就是到点的最远距离,环内的半径就是多边形的边的线段到点的最小距离
#include <bits/stdc++.h> #define maxn 100010 #define INF 0x3f3f3f3f typedef long long ll; using namespace std; double eps = 1e-6; #define Vector Point int dcmp(double x) { return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1); } struct Point { double x, y; Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数 Point(double x = 0.0, double y = 0.0): x(x), y(y) { } //构造函数 friend istream& operator >> (istream& in, Point& P) { return in >> P.x >> P.y; } friend ostream& operator << (ostream& out, const Point& P) { return out << P.x << ' ' << P.y; } friend Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); } friend Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); } friend Vector operator * (const Vector& A, const double& p) { return Vector(A.x*p, A.y*p); } friend Vector operator / (const Vector& A, const double& p) { return Vector(A.x/p, A.y/p); } friend bool operator == (const Point& A, const Point& B) { return dcmp(A.x-B.x) == 0 && dcmp(A.y-B.y) == 0; } friend bool operator < (const Point& A, const Point& B) { return A.x < B.x || (A.x == B.x && A.y < B.y); } void in(void) { scanf("%lf%lf", &x, &y); } void out(void) { printf("%lf %lf", x, y); } }a[maxn]; double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; } //点积 double Length(const Vector& A){ return sqrt(Dot(A, A)); } double Angle(const Vector& A, const Vector& B) { return acos(Dot(A, B)/Length(A)/Length(B)); } //向量夹角 double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; } //叉积 double Area(const Point& A, const Point& B, const Point& C) { return fabs(Cross(B-A, C-A)); } double f(const Point& P, const Point& A, const Point& B) { if (A == B) return Length(P - A); Vector v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(Dot(v1, v2)) < 0) return Length(v2); if (dcmp(Dot(v1, v3)) > 0) return Length(v3); return fabs(Cross(v1, v2)) / Length(v1); } int main(){ double x, y, x1, y1, ma = 0, mi=1e18; int n; scanf("%d%lf%lf", &n, &a[0].x, &a[0].y); for(int i=2;i<=n+1;i++) scanf("%lf%lf", &a[i].x, &a[i].y); a[1] = a[n+1]; for(int i=2;i<=n+1;i++){ double t = f(a[0], a[i], a[i-1]); mi = min(t, mi); ma = max(ma, Length(a[i]-a[0])); } printf("%.9f\n", (ma*ma-mi*mi)*acos(-1.0)); return 0; }
posted on 2018-03-27 20:53 2855669158 阅读(139) 评论(0) 编辑 收藏 举报