Advertisement
am1x

c47185_b.cpp

Jan 13th, 2025 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <assert.h>
  3. #include <inttypes.h>
  4. #include <math.h>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8.  
  9. const unsigned int N = 100000;
  10. const unsigned int C = 20;
  11. const int X = 2000000000;
  12.  
  13. struct Point {
  14.     int x, y;
  15.     Point(int _x, int _y) : x(_x), y(_y) {}
  16. };
  17.  
  18. struct Multi {
  19.     std::vector<Point> v;
  20.     unsigned int idx;
  21. };
  22.  
  23. bool operator< (const Multi &a, const Multi &b)
  24. {
  25.     Point p = a.v[0];
  26.     unsigned int l = b.v.size() - 1;
  27.     double alpha = 0;
  28.  
  29.     for (unsigned int i = 0; i < l; i++) {
  30.         double dx1 = b.v[i].x - (double) p.x;
  31.         double dy1 = b.v[i].y - (double) p.y;
  32.         double dx2 = b.v[i + 1].x - (double) p.x;
  33.         double dy2 = b.v[i + 1].y - (double) p.y;
  34.         double dx0 = b.v[i + 1].x - (double) b.v[i].x;
  35.         double dy0 = b.v[i + 1].y - (double) b.v[i].y;
  36.         double d21 = dx1 * dx1 + dy1 * dy1;
  37.         double d22 = dx2 * dx2 + dy2 * dy2;
  38.         double d20 = dx0 * dx0 + dy0 * dy0;
  39.         assert (d20 > 0);
  40.         double dz = dx1 * dy2 - dx2 * dy1;
  41.         assert (dz != 0);
  42.         double sa = dz, ca = 0.5 * (d21 + d22 - d20);
  43.         alpha += atan2(sa, ca);
  44.     }
  45.  
  46.     //printf("alpha = %.16f\n", alpha * 0.5);
  47.     return fabs(alpha) < 3;
  48. }
  49.  
  50. int main()
  51. {
  52.     unsigned int n = 0;
  53.     std::cin >> n;
  54.     assert (std::cin);
  55.     assert (3 <= n && n <= N);
  56.     std::vector<Multi> ms;
  57.     for (unsigned int i = 0; i < n; i++) {
  58.         unsigned int c = 0;
  59.         std::cin >> c;
  60.         assert (std::cin);
  61.         assert (3 <= c && c <= C);
  62.         Multi mi;
  63.         mi.idx = i;
  64.         mi.v.reserve(c + 1);
  65.  
  66.         for (unsigned int j = 0; j < c; j++) {
  67.             int x = 0, y = 0;
  68.             std::cin >> x >> y;
  69.             assert (std::cin);
  70.             assert (-X <= x && x <= X);
  71.             assert (-X <= y && y <= X);
  72.             mi.v.push_back(Point(x, y));
  73.         }
  74.         mi.v.push_back(mi.v[0]);
  75.         ms.push_back(mi);
  76.     }
  77.  
  78.     std::sort(ms.begin(), ms.end());
  79.     std::vector<unsigned int> res(n, 0);
  80.     for (unsigned int i = 0; i < n; i++) {
  81.         res[ms[i].idx] = i;
  82.     }
  83.     for (unsigned int i = 0; i < n; i++)
  84.         std::cout << res[i] << ' ';
  85.     std::cout << std::endl;
  86.     return 0;
  87. }
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement