Sha 1555 Garland
There are n lanterns, the first is A, and the last is B. The relationship between the lanterns is given, and the height of Each Lantern is required to be non-negative. The lowest is B.
Idea: The formula H [I] = 2 * H [I-1] + 2-H [I-2], then enumeration H [2], when we know H [1], we can find all the heights and determine whether all values are non-negative.
# Include
# Include
# Include
Using namespace std; const int MAXN = 1500; int n; double A, B, H [MAXN]; int check (double cnt) {H [1] = cnt; for (int I = 2; I <n; I ++) {H [I] = 2 * H [I-1] + 2-H [I-2]; if (H [I] <0) return 0;} B = H [n-1]; return true;} int main () {while (scanf ("% d % lf ", & n, & )! = EOF) {H [0] = A; double l =-1, r = MAXN; while (r-l> 1e-6) {double mid = (l + r) /2; if (check (mid) r = mid; else l = mid;} printf ("%. 2lf \ n ", B);} return 0 ;}