Title Address: POJ 1905
Test instructions: A piece of material made of a straight rod sandwiched between two walls, when the length of the heat when he is longer, will be due to the squeeze of the two walls upward uplift. The length change function is L ' = (1+n*c) *l, given the l,c,n, the height of the arch upward H.
Ideas:
The two formulas are calculated manually, and then the H value is found in two points.
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <sstream> #include <algorithm> #include <set> #include <queue> #include <stack> #include <map>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double pi= ACOs ( -1.0); const double Esp=1e-8;int main () { double l,n,c; Double s,h,r; Double Low,high,mid,ans; while (~scanf ("%lf%lf%lf", &l,&n,&c)) { if (l==-1&&n==-1&&c==-1) break; low=0; High=0.5*l; S= (1+n*c) *l; while (HIGH-LOW>ESP) { mid= (low+high) *0.5; R= (4*mid*mid+l*l)/(8*mid); if (2*r*asin (L/(2*R)) <s) { low=mid; } else high=mid; } printf ("%.3lf\n", mid); } return 0;}
POJ 1905-expanding Rods (dichotomy + computational geometry)