fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,m; scanf("%d %d",&n,&m);
  7. double r; scanf("%lf",&r);
  8. double inp, sum = 0;
  9. for(int i = 0; i < n; i++) {
  10. double b = 0.5;
  11. bool t = true;
  12. for(int j = 0; j < m; j++){
  13. scanf("%lf", &inp);
  14. if(inp > 0 && t) {
  15. t = false;
  16. b = inp;
  17. }
  18. }
  19. sum += b*pow(r,n-i-1);
  20. }
  21. printf("%lf",sum);
  22. return 0;
  23. }
Success #stdin #stdout 0s 3300KB
stdin
2 4
2.71 
-9.0 -8.8 -7.3  7.5
-6.3 -9.7  6.8 -0.5 
stdout
27.125000