Skip to content

Instantly share code, notes, and snippets.

@potetisensei
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potetisensei/6df83bccd1040c7ab1bc to your computer and use it in GitHub Desktop.
Save potetisensei/6df83bccd1040c7ab1bc to your computer and use it in GitHub Desktop.
POJ 1759
#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