fork(3) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. struct dot {
  7. double x;
  8. double y;
  9. double z;
  10. dot() {
  11. x=0;
  12. y=0;
  13. z=0;
  14. }
  15. dot (double a, double b, double c) {
  16. x=a;
  17. y=b;
  18. z=c;
  19. }
  20. };
  21. int main() {
  22. vector <dot> a;
  23. double x, y, z, p;
  24. double sump=0;
  25. dot sum=dot();
  26. while (cin>>x &&
  27. cin>>y &&
  28. cin>>z &&
  29. cin>>p)
  30. {
  31. a.push_back(dot(x,y,z));
  32. sum.x+=x*p;
  33. sum.y+=y*p;
  34. sum.z+=z*p;
  35. sump+=p;
  36. }
  37. sum.x/=sump;
  38. sum.y/=sump;
  39. sum.z/=sump;
  40.  
  41. cout << sum.x << " " << sum.y << " " << sum.z << endl;
  42.  
  43. for (int i=0; i<a.size(); i++)
  44. {
  45. double l=sqrt((a[i].x-sum.x)*(a[i].x-sum.x) + (a[i].y-sum.y)*(a[i].y-sum.y) + (a[i].z-sum.z)*(a[i].z-sum.z));
  46. cout << l << endl;
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0s 15232KB
stdin
2 2 1 2
3 1 2 1
stdout
2.33333 1.66667 1.33333
0.57735
1.1547