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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
#include <bits/stdc++.h> #define all(vec) vec.begin(),vec.end() #define lson(o) (o<<1) #define rson(o) (o<<1|1) #define SZ(a) ((long long) a.size()) #define debug(var) cerr << #var <<":"<<var<<"\n"; #define cend cerr<<"\n-----------\n" #define fsp(x) fixed<<setprecision(x)
using namespace std;
using ll = long long; using ull = unsigned long long; using DB = double;
using CD = complex<double>;
static constexpr ll MAXN = (ll) 1e6 + 10, INF = (1ll << 61) - 1; static constexpr ll mod = 998244353; static constexpr double eps = 1e-8; const double pi = acos(-1.0);
ll lT;
using Real = ll; int sgn(auto x) { if (-eps < x && x < eps) return 0; return x < 0 ? -1 : 1; } struct Point { Real x, y; ll idx;
explicit Point(Real x_ = 0, Real y_ = 0) : x(x_), y(y_) {}
Point &operator+=(Point p) & { x += p.x, y += p.y; return *this; } Point &operator-=(Point p) & { x -= p.x, y -= p.y; return *this; } Point &operator*=(Real t) & { x *= t, y *= t; return *this; } Point &operator/=(Real t) & { x /= t, y /= t; return *this; }
Point operator-() const { return Point(-x, -y); }
friend Point operator+(Point a, Point b) { return a += b; } friend Point operator-(Point a, Point b) { return a -= b; } friend Point operator*(Point a, Real b) { return a *= b; } friend Point operator*(Real a, Point b) { return b *= a; } friend Point operator/(Point a, Real b) { return a /= b; }
friend bool operator<(Point a, Point b) { int sx = sgn(a.x - b.x); if (sx != 0) return a.x < b.x; return a.y < b.y; } friend bool operator>(Point a, Point b) { return b < a; } friend bool operator==(Point a, Point b) { return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0; } friend bool operator!=(Point a, Point b) { return !(a == b); }
friend istream &operator>>(istream &is, Point &p) { return is >> p.x >> p.y; }
Real norm() const { return x * x + y * y; } DB abs() const { return sqrt(norm()); } }; using Vector = Point; auto cross(Point a,Point b){ if constexpr (is_integral_v<Real>) { return (__int128_t)a.x*b.y-(__int128_t)a.y*b.x; }else { return a.x*b.y-a.y*b.x; } }
auto dot(Point a,Point b){ if constexpr (is_integral_v<Real>) { return (__int128_t)a.x*b.x+(__int128_t)a.y*b.y; }else { return a.x*b.x+a.y*b.y; } }
struct Line{ Point p1,p2; Line(){} Line(Point a,Point b):p1(a),p2(b) {} friend bool operator<(Line a,Line b){ if(a.p1!=b.p1) return a.p1<b.p1; return a.p2<b.p2; } friend bool operator==(Line a,Line b){ if(a.p1!=b.p1) return false; if(a.p2!=b.p2) return false; return true; } friend istream& operator>>(istream& is, Line& e) { Real a,b,c,d; is >> a >> b >> c >> d; e = Line(Point(a,b),Point(c,d)); return is; } };
Point project(Point p,Line l){ Point vec=l.p2-l.p1; DB r = dot(vec,p-l.p1)/((DB)vec.x*vec.x+vec.y*vec.y); return l.p1+vec*r; } Point reflect(Point p,Line l){ Point proj=project(p, l); return proj+proj-p; } mt19937 rng(233);
#define ON_SEGMENT 0 #define COUNTER_CLOCKWISE 1 #define CLOCKWISE (-1) #define ONLINE_BACK 2 #define ONLINE_FRONT (-2)
int CCW(Point p,Line l){ Vector a=l.p2-l.p1,b=p-l.p1; if(sgn(cross(a,b))>0){ return COUNTER_CLOCKWISE; } if(sgn(cross(a,b))<0){ return CLOCKWISE; } if(sgn(dot(a, b))<0){ return ONLINE_BACK; } if(a.norm()<b.norm()) return ONLINE_FRONT; return ON_SEGMENT; }
bool isOrthogonal(Line a,Line b){ Vector c=a.p2-a.p1,d=b.p2-b.p1; return !sgn(dot(c,d)); } bool isParallel(Line a,Line b){ Vector c=a.p2-a.p1,d=b.p2-b.p1; return !sgn(cross(c,d)); } bool isIntersect(Line a,Line b){ return CCW(b.p1,a)*CCW(b.p2,a)<=0 && CCW(a.p1,b)*CCW(a.p2,b)<=0; }
Point getintersect(const Line &a,const Line &b){ Point p=a.p1, v=a.p2-a.p1,q=b.p1,w=b.p2-b.p1; Point u=p-q; DB t=cross(w,u)/cross(v,w); return p+v*t; }
DB distancePL(Point p,Line l){ auto val=cross(l.p2-l.p1,p-l.p1); return sgn(val)*val/(l.p2-l.p1).abs(); } DB distancePS(Point p,Line l){ Vector t=l.p2-l.p1; if(sgn(dot(t,p-l.p1))<0){ return (p-l.p1).abs(); } if(sgn(dot(t,p-l.p2))>0){ return (p-l.p2).abs(); } return distancePL(p, l); } DB distanceSS(Line a,Line b){ if(isIntersect(a, b)) return 0; return min({distancePS(a.p1, b),distancePS(a.p2,b),distancePS(b.p1, a),distancePS(b.p2, a)}); } DB polygonArea(const vector<Point> &poly){ DB res=0; for (int i=0;i<poly.size();++i){ res+=cross(poly[i],poly[(i+1)%SZ(poly)])/2; } res=abs(res); return res; }
bool isConvex(const vector<Point> &poly){ for (int i=0;i<poly.size();++i){ ll i1=(i+1)%SZ(poly),i2=(i+2)%SZ(poly); Vector a=poly[i]-poly[i1],b=poly[i2]-poly[i1]; if(sgn(cross(a,b))>0){ return false; } } return true; }
int isInPolygon(Point p,const vector<Point> &poly){ ll res=0; Line l(p,p+Point(2e5,rng())); for (int i=0;i<poly.size();++i){ int i1=(i+1)%SZ(poly); Line seg=Line(poly[i],poly[i1]); int ccw=CCW(p,seg); if(ccw==ON_SEGMENT){ return 1; } if(isIntersect(l,seg)){ ++res; } } if(res&1) return 2; return 0; }
int get_part_of_point(const Point &p) { if (p.y < 0) return 0; if (p.y == 0 && p.x >= 0) return 1; return 2; }
void polar_angle_sort(vector<Point> &poly) { sort(poly.begin(),poly.end(),[](const Point &a,const Point &b)->bool { int part1=get_part_of_point(a),part2=get_part_of_point(b); if (part1!=part2) { return part1<part2; } return sgn(cross(a,b))==1; }); }
void Solve() { ll N; cin >> N; vector<Point> poly(N); for (int i=0;i<N;++i) { cin>>poly[i]; poly[i].idx=i+1; } polar_angle_sort(poly); for (int i=0;i<N;++i) { cout<<poly[i].idx<<" "; } }
signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
Solve(); return 0; }
|