题意:
已知x,y,l,d,要求判断汽车能不能安全通过该转角。
思路:
三分角度,求解h 的最大值,若max>y的话,则汽车能安全通过,否则便不能安全通过。
代码如下:
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <list> #include <vector> #include <map> #include <algorithm> #define LL long long #define LLU unsigned long long #define INF 0x7fffffff #define eps 1e-7 const double PI = acos(-1.0); using namespace std; double calcu(double x, double l, double d, double sita) { return (l-(x-d*sin(sita))/cos(sita))*sin(sita)+d*cos(sita); } int main() { double x, y, l, d; while(~scanf("%lf%lf%lf%lf",&x, &y, &l, &d)) { double L = 0, R = PI/2; double mid, midmid, t1, t2; while(R-L>eps) { mid = (L+R)/2; midmid = (R+mid)/2; t1 = calcu(x,l,d,mid); t2 = calcu(x,l,d,midmid); if(t1>t2) R = midmid; else L = mid; } if(y-calcu(x,l,d,L)>eps) printf("yes\n"); else printf("no\n"); } return 0; }