fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Dot {
  6. double x;
  7. double y;
  8. double z;
  9. public Dot() {
  10. x = 0;
  11. y = 0;
  12. z = 0;
  13. }
  14. Dot (double a, double b, double c) {
  15. x=a;
  16. y=b;
  17. z=c;
  18. }
  19. }
  20. class Ideone{
  21. public static void main (String[] args) throws java.lang.Exception{
  22. Scanner in = new Scanner(System.in);
  23. Vector a = new Vector();
  24. double x, y, z, p;
  25. double sump=0;
  26. Dot sum = new Dot();
  27. while (in.hasNextDouble()){
  28. x = in.nextDouble();
  29. y = in.nextDouble();
  30. z = in.nextDouble();
  31. p = in.nextDouble();
  32. a.add(new Dot(x,y,z));
  33.  
  34. sum.x += x*p;
  35. sum.y += y*p;
  36. sum.z += z*p;
  37. sump+=p;
  38. }
  39. sum.x/=sump;
  40. sum.y/=sump;
  41. sum.z/=sump;
  42.  
  43. System.out.println(sum.x + " " + sum.y + " " + sum.z);
  44. Dot dot;
  45. for (int i=0; i<a.size(); i++)
  46. {
  47. dot = (Dot)a.elementAt(i);
  48. double l = Math.sqrt((dot.x-sum.x)*(dot.x-sum.x) + (dot.y-sum.y)*(dot.y-sum.y) + (dot.z-sum.z)*(dot.z-sum.z));
  49. System.out.println(l);
  50. }
  51. }
  52. }
Success #stdin #stdout 0.07s 4386816KB
stdin
7 10 5 20
1 0 3 1
43 50 6 3
0 9 0 200
4 8 15 66
stdout
1.8413793103448275 9.23448275862069 3.831034482758621
5.344517232368776
9.309898456732652
57.97037057365674
4.257051225524774
11.442437751129175