Guest User

Untitled

a guest
Nov 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double c, array [ 10 ], y, sum, tmp;
  7. int n;
  8.  
  9. double bs ( double a, double b ) {
  10. c = ( a + b ) / 2;
  11. sum = 0;
  12. tmp = 1;
  13. for ( int i = 1; i <= n; ++i ) {
  14. tmp *= 1 + c;
  15. sum += array [ n - i ] * tmp;
  16. }
  17. if ( abs( b - a ) <= 0.00000001 ) return c;
  18. if ( sum > y ){ return bs ( a, c - 0.00001 ); } else { return bs ( c, b ); }
  19. }
  20.  
  21. int main ( void ) {
  22. scanf ( "%d", &n );
  23. for ( int i = 0; i < n; ++i ) {
  24. scanf ( "%lf", &array [ i ] );
  25. }
  26. scanf ( "%lf", &y );
  27. printf ( "%.2lf\n", 100 * bs ( -1, 1 ) );
  28. return 0;
  29. }
Add Comment
Please, Sign In to add comment