fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define PI acos(-1)
  5. int N;
  6.  
  7. double get_angle(int sz) {
  8. int dot = (-sz * 2) + (sz - 1);
  9. int len = (sz) + (sz) * (sz);
  10. return acos(dot *1.0 / len*1.0);
  11. }
  12.  
  13. void solve(vector<vector<double> >& pts, int cur) {
  14. if (cur == N+2) return;
  15. double theta = get_angle(cur - 1) - PI / 2;
  16. for (int i = 0; i < pts.size(); i++) {
  17. for (int k = 0; k < pts[i].size(); k++) {
  18. pts[i][k] *= cos(theta);
  19. }
  20. pts[i].push_back(-sin(theta));
  21. }
  22. vector<double> new_pt;
  23. for (int i = 2; i < cur; i++) new_pt.push_back(0);
  24. new_pt.push_back(1);
  25. pts.push_back(new_pt);
  26.  
  27. solve(pts, cur + 1);
  28. }
  29.  
  30. int main() {
  31.  
  32. cout << fixed << setprecision(9);
  33.  
  34. int T; cin >> T;
  35. while (T) {
  36. cin >> N;
  37. if (N == 1) {
  38. cout << 1 << "\n" << -1 << "\n";
  39. } else {
  40. vector<vector<double> > pts;
  41. vector<double> p1, p2;
  42. p1.push_back(1);
  43. p2.push_back(-1);
  44. pts.push_back(p1); pts.push_back(p2);
  45. solve(pts, 3);
  46.  
  47. for (int i = 0; i < pts.size(); i++) {
  48. for (int k = 0; k < pts[i].size(); k++) {
  49. cout << pts[i][k] << " ";
  50. } cout << "\n";
  51. }
  52. }
  53. cout << "\n";
  54. T--;
  55. }
  56.  
  57. return 0;
  58. }
Time limit exceeded #stdin #stdout 5s 65216KB
stdin
Standard input is empty
stdout
Standard output is empty