2013年10月18日 星期五

UVa 11666 - Logarithms

Problem link

Keyword: math

Algorithm:

ln( 1-x ) is defined as stated.
According to the statement, ln( n ) = L + ln( 1-x )
L = ln( n ) - ln( 1-x ) = ln( n / (1-x) )
To get the minimum L, we need L to be ceil( ln( n ) ).
However, please note that x can be negative.
I got a WA for that.

Code:
#include<cstdio>
#include<cmath>

int main()
{
    int n;

    while( scanf( "%d", &n ) && n )
    {
        int expo = ceil( log( n ) );
        if( n / exp( expo-1 ) <= 2 )
            printf( "%d %.8lf\n", expo-1, 1 - n / exp( expo-1 ) );
        else
            printf( "%d %.8lf\n", expo, 1 - n / exp( expo ) );
    }

    return 0;
}

沒有留言:

張貼留言