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
| #include <iostream> #include <cstdio> #include <cmath> #include <algorithm>
using namespace std;
const double pi = acos(-1.0); const double eps = 1e-8; const int maxn = 50010; const double max_length = 1e6; const double max_enough = 9e8; const int max_iterator = 50;
inline int dcmp(double x){ if(fabs(x)<eps) return 0; return (x > 0 ? 1 : -1); }
struct Point{
double x, y;
Point(){ x = 0; y = 0; } Point(double _x, double _y){ x = _x; y = _y; }
bool operator <(const Point &b)const{ return (dcmp(x - b.x) == 0 ? dcmp(y - b.y) < 0 : x < b.x); } Point operator+(const Point &b)const{ return Point(x + b.x, y + b.y); } Point operator-(const Point &b)const{ return Point(x - b.x, y - b.y); }
};
struct Line{ Point p1, p2; Line(){
} Line(Point _p1, Point _p2){ p1 = _p1; p2 = _p2; } double theta(){ return atan2(p2.y - p1.y, p2.x - p1.x); } double getA(){ return p1.y - p2.y; } double getB(){ return p2.x - p1.x; } double getC(){ return p1.x * p2.y - p2.x * p1.y; } };
Point getCrossPoint(Line l1, Line l2){ double A1 = l1.getA(), B1 = l1.getB(), C1 = l1.getC(); double A2 = l2.getA(), B2 = l2.getB(), C2 = l2.getC(); double x_cross = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1); double y_cross = (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1);
return Point(x_cross, y_cross); }
struct Ponit_with_i{ Point p; int i; Ponit_with_i(){} Ponit_with_i(Point _p, int _i){ p = _p; i = _i; } bool operator<(const Ponit_with_i &b) const{ return dcmp(p.y - b.p.y) < 0; } };
Line l1, l2; Point p[maxn]; Ponit_with_i pwi[maxn];
int n, T;
int main(){ scanf("%d", &T);
while(T--){ scanf("%d", &n);
for(int i = 0;i < n;i++) scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p, p+n);
double delta = 0;
if(p[n/2-1].x == p[n/2].x) delta = 1.00; Point p1_l1(p[n/2-1].x - delta, -max_enough); Point p2_l1(p[n/2].x + delta, max_enough); l1 = Line(p1_l1, p2_l1);
int p_l2_index = 0; double theta_l2 = 0;
double left = l1.theta() - pi; double right = l1.theta(); double mid; bool isFind = false; int cnt = 1;
while(cnt <= max_iterator && !isFind){ cnt ++; mid = left + (right - left) / 2.00; Point base(max_length * cos(mid), max_length * sin(mid)); for(int i = 0;i < n;i++){ pwi[i] = Ponit_with_i(getCrossPoint(l1, Line(p[i], p[i] + base) ), i); }
sort(pwi, pwi + n); int l_num = 0; int r_num = 0; if(pwi[0].i < n / 2) l_num++; else r_num ++;
for(int i = 1;i < n;i++){ if(dcmp(pwi[i - 1].p.y - pwi[i].p.y) == 0){ if(pwi[i].i < n/2) l_num++; else r_num++; } else{ if(l_num == n/4 && r_num == n/4){ isFind = true; p_l2_index = pwi[i-1].i; theta_l2 = mid; break; } else if(l_num >= n/4){ left = mid; break; } else if(r_num >= n/4){ right = mid; break; } if(pwi[i].i < n / 2) l_num ++; else r_num ++; } } }
delta = 0.9999; Point p2_l2(max_enough * cos(theta_l2), max_enough * sin(theta_l2)); p[p_l2_index].y += delta; l2 = Line(p[p_l2_index] + p2_l2, p[p_l2_index] - p2_l2); printf("%d %d %d %d\n", (int)round(l1.p1.x), (int)round(l1.p1.y), (int)round(l1.p2.x), (int)round(l1.p2.y)); printf("%d %d %d %d\n", (int)round(l2.p1.x), (int)round(l2.p1.y), (int)round(l2.p2.x), (int)round(l2.p2.y)); }
return 0; }
|