fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. static Scanner sc = new Scanner(System.in);
  8.  
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. int n, m;
  12. n = sc.nextInt();
  13. m = sc.nextInt();
  14. double r = sc.nextDouble();
  15. double[][] a = new double[n][m];
  16. for(int i = 0; i < n; i++){
  17. for(int j = 0; j < m; j++){
  18. a[i][j] = sc.nextDouble();
  19. }
  20. }
  21. double sum = 0;
  22. for(int i = 0; i < n; i++){
  23. double b = 0.5;
  24. for(int j = 0; j < m; j++){
  25. if(a[i][j] > 0){
  26. b = a[i][j];
  27. break;
  28. }
  29. }
  30. sum += b*Math.pow(r, n-i-1);
  31. }
  32. System.out.println(sum);
  33. }
  34. }
Success #stdin #stdout 0.17s 321344KB
stdin
2 2
2.5
-1 1
1 0
stdout
3.5