Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef complex<double> cd;
  5.  
  6. typedef vector<vector<cd>> matrix;
  7.  
  8. matrix operator*(matrix& a, matrix& b) {
  9.     matrix ans(2, vector<cd>(2, 0));
  10.     for (int i = 0;i < 2;i++) {
  11.         for (int j = 0;j < 2;j++) {
  12.             for (int k = 0;k < 2;k++) {
  13.                 ans[i][j] += a[i][j + k] * b[j + k][i];
  14.             }
  15.         }
  16.     }
  17.     return ans;
  18. }
  19.  
  20. matrix xp(matrix& b, int e) {
  21.     if (e == 1) return b;
  22.     matrix c = xp(b, e / 2);
  23.     c = c * c;
  24.     if (e & 1) c = c * b;
  25.     return c;
  26. }
  27.  
  28. int main() {
  29.     int t;
  30.     cin >> t;
  31.     int alf, n;
  32.     double l;
  33.     matrix base = {{0, 1}, {1, 1}};
  34.     while (t--) {
  35.         cin >> alf >> l >> n;
  36.         double alfa = acos(-1) * alf / 180.0;
  37.         base[0][0] = cd(cos(alfa), sin(alfa));
  38.         auto exp = xp(base, n);
  39.         cd pos = (base[0][1] + base[1][1]) * l;
  40.         printf("%.2f %.2f\n", pos.real(), pos.imag());
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement