Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cmath>
- using namespace std;
- double c, array [ 10 ], y, sum, tmp;
- int n;
- double bs ( double a, double b ) {
- c = ( a + b ) / 2;
- sum = 0;
- tmp = 1;
- for ( int i = 1; i <= n; ++i ) {
- tmp *= 1 + c;
- sum += array [ n - i ] * tmp;
- }
- if ( abs( b - a ) <= 0.00000001 ) return c;
- if ( sum > y ){ return bs ( a, c - 0.00001 ); } else { return bs ( c, b ); }
- }
- int main ( void ) {
- scanf ( "%d", &n );
- for ( int i = 0; i < n; ++i ) {
- scanf ( "%lf", &array [ i ] );
- }
- scanf ( "%lf", &y );
- printf ( "%.2lf\n", 100 * bs ( -1, 1 ) );
- return 0;
- }
Add Comment
Please, Sign In to add comment