Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include<stdio.h>
- #include<iostream>
- #include<vector>
- #include<cmath>
- #include<algorithm>
- #include<memory.h>
- #include<map>
- #include<set>
- #include<queue>
- #include<list>
- #include<sstream>
- #include<cstring>
- #include<numeric>
- #include<limits.h>
- using namespace std;
- const int N = 1e5;
- struct point{
- private:
- double x, y;
- public:
- point() {}
- point(double x, double y) : x(x), y(y) {}
- void scan() {
- scanf("%lf%ld", &x, &y);
- }
- point operator-(const point & A) const {
- return point(x - A.x, y - A.y);
- }
- double operator* (const point & A) const {
- return x * A.y - y * A.x;
- }
- double operator% (const point & A) const {
- return x * A.x + y * A.y;
- }
- double dist(const point & A) const {
- point r = A - *this;
- return r.val();
- }
- double val() {
- return hypot(x, y);
- }
- } a[N];
- int main(){
- int n;
- scanf("%d", &n);
- point P;
- P.scan();
- for (int i = 0; i < n; i++) {
- a[i].scan();
- }
- a[n] = a[0];
- bool minus = false;
- bool plus = false;
- double res = 1e12;
- for (int i = 0; i<n; i++)
- {
- double val = (a[i] - P) * (a[i + 1] - P);
- if ((P - a[i]) % (a[i + 1] - a[i]) < 0)
- res = min(res, a[i].dist(P));
- else {
- res = min(res, ((P - a[i + 1]) % (a[i] - a[i + 1])) < 0 ?
- a[i + 1].dist(P) :
- abs(val) / ((a[i] - a[i + 1]).val())
- );
- }
- if (val > 0)
- plus = true;
- else
- if (val < 0)
- minus = true;
- }
- if (!(plus && minus))
- {
- printf("0.000");
- return 0;
- }
- printf("%.3lf", res * 2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement