Last active
August 29, 2015 14:25
-
-
Save potetisensei/6df83bccd1040c7ab1bc to your computer and use it in GitHub Desktop.
POJ 1759
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
#include <algorithm> | |
using namespace std; | |
#define EPS 10e-3 | |
int N; | |
double A; | |
double high; | |
double low; | |
double ans; | |
double check(double t) { | |
double a = A; | |
double b = t; | |
for (int i=3; i<=N; i++) { | |
double x = 2*b - a + 2; | |
if (x < 0) return -1.0; | |
a = b; | |
b = x; | |
} | |
return b; | |
} | |
int main() { | |
scanf("%d", &N); | |
scanf("%lf", &A); | |
high = 1000000.00; | |
ans = high; | |
low = 0.00; | |
for (int i=0; i<10000; i++) { | |
double mid = (high+low)/2; | |
double ret = check(mid); | |
if (ret > -1.0) { | |
high = mid; | |
ans = min(ans, ret); | |
} | |
else low = mid; | |
} | |
printf("%.2f\n", ans); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment