Advertisement
Guest User

Untitled

a guest
Jul 25th, 2020
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using Point = complex<double>;
  5.  
  6. Point perp(Point p) { return {-p.imag(), p.real()}; }
  7.  
  8. int main() {
  9.   ifstream cin("expand.in");
  10.   ofstream cout("expand.out");
  11.  
  12.   int _t, n; double r;
  13.   cin >> _t >> n >> r; r += 1e-7;
  14.   vector<Point> pts;
  15.   for (int i = 0; i < n; ++i) {
  16.     double x, y; cin >> x >> y;
  17.     pts.emplace_back(x, y);
  18.   }
  19.  
  20.   vector<Point> sol = pts;
  21.   for (int it = 0; it < 300; ++it) {
  22.     int idx = it % n;
  23.     Point a = sol[(idx + n - 1) % n], b = sol[(idx + 1) % n];
  24.     Point ref = pts[idx];
  25.     Point d = perp(b - a);
  26.     sol[idx] = ref - d / abs(d) * r;
  27.   }
  28.  
  29.   cout << fixed << setprecision(20);
  30.   for (int i = 0; i < n; ++i)
  31.     cout << sol[i].real() << " " << sol[i].imag() << '\n';
  32.  
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement