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
   |  #include<bits/stdc++.h> #define x first #define y second #define ok cout << "ok" << endl; using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const double PI = acos(-1.0); const int INF=0x3f3f3f3f; const ll LINF=0x3f3f3f3f3f3f3f3f; const int N=1e5+9; const int shift=1e3+9; const double Eps=1e-7;
  typedef pair<long double, long double> point; point a[N], c; long double ang[N], angle, dist[N], bx, by; int n, q, t1, t2;
  point getC() {     long double area = 0, cx = 0, cy = 0;     for(int i = 0; i < n; i++) {         long double temp = a[i].x * a[(i+1)%n].y - a[i].y * a[(i+1)%n].x;         area += temp;         cx += (a[i].x + a[(i+1)%n].x) * temp;         cy += (a[i].y + a[(i+1)%n].y) * temp;     }     area /= 2;     cx /= 6 * area;     cy /= 6 * area;     return point(cx, cy); }
  point getPoint(int idx) {     return point(c.x + dist[idx] * cosl(angle + ang[idx]), c.y + dist[idx] * sinl(angle + ang[idx])); }
  long double getDist(point a, point b) {     return sqrtl((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
  int main(void) {     if(fopen("in", "r")!=NULL) {freopen("in", "r", stdin); freopen("out", "w", stdout);}     scanf("%d%d", &n, &q);     for(int i = 0; i < n; i++) {         scanf("%d%d", &t1, &t2);         a[i].x = t1;         a[i].y = t2;     }     bx = a[0].x, by = a[0].y;     for(int i = 0; i < n; i++) {         a[i].x -= bx;         a[i].y -= by;     }     c = getC();     for(int i = 0; i < n; i++) {         dist[i] = getDist(a[i], c);         ang[i] = atan2l(a[i].y - c.y, a[i].x - c.x);         if(ang[i] < 0)             ang[i] += 2 * PI;     }     angle = 0;     int i = 0, j = 1, op, x, y;     point top, nxt;     while(q--) {         scanf("%d", &op);         if(op == 1) {             scanf("%d%d", &x, &y);             x--, y--;             if(x == i) {                 i = y;                 top = getPoint(j);                 nxt = point(top.x, top.y - dist[j]);             }             else {                 j = y;                 top = getPoint(i);                 nxt = point(top.x, top.y - dist[i]);             }             angle += -PI/2 - atan2l(c.y - top.y, c.x - top.x);             while(angle < 0)                 angle += 2 * PI;             while(angle >= 2 * PI)                 angle -= 2 * PI;             c = nxt;         }         else {             scanf("%d", &x);             point ans = getPoint(x-1);             printf("%.10f %.10f\n", (double)(ans.x + bx), (double)(ans.y + by));         }     }
      return 0; }
 
  |