fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <cassert>
  5.  
  6. typedef std::vector<double> Points;
  7.  
  8. double l(const Points &points)
  9. {
  10. double sum = 0;
  11. for(int i = 0; i < points.size(); ++i)
  12. sum += (points[i]*points[i]);
  13. return std::sqrt(sum);
  14. };
  15. Points n(Points points)
  16. {
  17. double length = l(points);
  18. for(int i = 0; i < points.size(); ++i)
  19. points[i] /= length;
  20. return points;
  21. };
  22. double d(const Points &a, const Points &b)
  23. {
  24. double sum = 0;
  25. assert(a.size() == b.size());
  26. for(int i = 0; i < a.size(); ++i)
  27. sum += (a[i]*b[i]);
  28. return sum;
  29. };
  30.  
  31. int main()
  32. {
  33. int N = 0;
  34. std::cin >> N;
  35.  
  36. std::vector<Points> P;
  37. for(;N > 0; --N)
  38. {
  39. int A = 0;
  40. double R = 0;
  41. std::cin >> A;
  42.  
  43. Points points;
  44. for(;A > 0; --A)
  45. {
  46. std::cin >> R;
  47. points.push_back(R);
  48. }
  49. P.push_back(points);
  50. }
  51.  
  52. std::cin >> N;
  53. std::vector<Points > O;
  54. for(;N > 0; --N)
  55. {
  56. Points o;
  57. char C = 0;
  58. int I = 0;
  59. std::cin >> C >> I;
  60.  
  61. if(C == 'l')
  62. o.push_back(l(P[I]));
  63. else if(C == 'n')
  64. {
  65. Points p = n(P[I]);
  66. for(int i = 0; i < p.size(); ++i)
  67. o.push_back(p[i]);
  68. }
  69. else if(C == 'd')
  70. {
  71. int I2 = 0;
  72. std::cin >> I2;
  73. o.push_back(d(P[I], P[I2]));
  74. }
  75. O.push_back(o);
  76. }
  77.  
  78. std::cout << std::endl;
  79. for(int i = 0; i < O.size(); ++i)
  80. {
  81. for(int e = 0; e < O[i].size(); ++e)
  82. std::cout << O[i][e] << " ";
  83. std::cout << std::endl;
  84. }
  85. return 0;
  86. }
Success #stdin #stdout 0s 3040KB
stdin
5
2 1 1
2 1.2 3.4
3 6.78269 6.72 6.76312
4 0 1 0 1
7 84.82 121.00 467.05 142.14 592.55 971.79 795.33
7
l 0
l 3
l 4
n 1
n 2
n 3
d 0 1
stdout
1.41421 
1.41421 
1479.26 
0.33282 0.94299 
0.579689 0.574332 0.578017 
0 0.707107 0 0.707107 
4.6