1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
| #include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double inf = 1e20; const double pi = acos(-1.0); const int maxp = 10100; int sgn(double x) { if(fabs(x) < eps) return 0; if(x < 0) return -1; else return 1; } double sqr(double x){ return x * x;} struct Point { double x,y; Point(){}; Point (double _x, double _y) { x = _x,y = _y; } bool operator == (const Point b) { return sgn(x - b.x) == 0 && sgn(y - b.y) == 0; } bool operator < (const Point b) { return sgn(x - b.x) == 0 ? sgn(y - b.y) < 0:x < b.x; } Point operator -(const Point b) { return Point(x - b.x,y - b.y); } Point operator +(const Point b) { return Point(x + b.x,y + b.y); } Point operator *(const double k) { return Point(x * k,y * k); } Point operator /(const double k) { return Point(x / k,y / k); } double operator ^(const Point b) { return x * b.y - y * b.x; } double operator *(const Point b) { return x * b.x + y * b.y; } double operator ^(const Point &b)const { return x * b.y - y * b.x; } double len() { return sqrt(x * x + y * y); } double len2() { return x * x + y * y; } double dis(const Point b) { return sqrt((x - b.x) * (x - b.x) + (y - b.y) * (y - b.y)); } double rad(Point a,Point b) { Point p = *this; return fabs(atan2(fabs((a - p) ^ (b - p)),(a - p) * (b - p))); } Point trunc(double r) { double l = len(); if(!sgn(l)) return *this; r /= l; return Point(x * r,y * r); } }; typedef Point Vec2; struct Line { Point s,e; Line(){} Line(Point _s,Point _e) { s = _s,e = _e; } bool operator ==(const Line v) { return (s == v.s) && (e == v.e); } Line (Point p,double angle) { s = p; if(sgn(angle - pi / 2) == 0) { e = (s + Point(0,1)); }else { e = (s + Point(1,tan(angle))); } } Line(double a,double b,double c) { if(sgn(a) == 0) { s = Point(0,-c / b); e = Point(1,-c / b); }else if(sgn(b == 0)) { s = Point(-c / a,0); e = Point(-c / a,1); } else { s = Point(0,-c / b); e = Point(1,(-c - a) / b); } } void adjust() { if(e < s) swap(s,e); } bool pointonseg(Point p) { return sgn((p - s) ^ (e - s)) == 0 && sgn((p - s) ^ (p - e)) <= 0; } double length() { return s.dis(e); } bool paraller(Line v) { return sgn((e - s)^(v.e - v.s)) == 0; } double dispointtoline(Point p) { return fabs((p - s) ^ (e - s)) / length(); } double dispointtoseg(Point p) { if(sgn((p - s) * (e - s)) < 0 || sgn((p - e) * (s - e)) < 0) {
return min(p.dis(s),p.dis(e)); }
return dispointtoline(p); } }; Point make_circle(Point a,Point b,Point c) { double a1 = b.x - a.x, b1 = b.y - a.y,c1 = (a1 * a1 + b1 * b1) / 2; double a2 = c.x - a.x, b2 = c.y - a.y,c2 = (a2 * a2 + b2 * b2) / 2; double d = a1 * b2 -a2 * b1; return Point(a.x + (c1 * b2 - c2 * b1) / d,a.y+(a1 * c2 - a2 * c1) / d); } double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } bool inter(Line l1,Line l2) { return max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) && max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) && max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) && max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) && sgn((l2.s-l1.s)^(l1.e-l1.s))*sgn((l2.e-l1.s)^(l1.e-l1.s)) <= 0 && sgn((l1.s-l2.s)^(l2.e-l2.s))*sgn((l1.e-l2.s)^(l2.e-l2.s)) <= 0; } Point shleter[maxp],typhoon[maxp]; Line lines[maxp]; int main() { int n,m; scanf("%d %d",&m,&n); for(int i = 1;i <= m;++i) { scanf("%lf %lf",&typhoon[i].x,&typhoon[i].y);
} for(int i = 1;i <= n;++i) { scanf("%lf %lf",&shleter[i].x,&shleter[i].y); } for(int i = 1;i < m;++i) { lines[i] = Line(typhoon[i],typhoon[i + 1]); } for(int i = 1;i <= n;++i) { double mn = 1e18; for(int j = 1;j < m;++j) { double temp = lines[j].dispointtoseg(shleter[i]); mn = min(mn,temp); } printf("%.4lf\n",mn); } }
|