HDU 2438 (三分)

来源:互联网 发布:淘宝好的名牌原单店 编辑:程序博客网 时间:2024/06/05 04:33

不知道为什么要加特判才能过~~

#include <bits/stdc++.h>using namespace std;#define eps 1e-10#define pi acos (-1)double x, y, l, d;double f (double t) {    return tan (t)*(-y) + l*sin (t) + d/(cos (t)) - x;}double solve () {    double L = 0.0, R = pi/2.0, LL, RR;    while (R-L > eps) {        LL = (2*L+R)/3.0, RR = (2*R+L)/3.0;        double p1 = f (LL), p2 = f (RR);        if (p2 >= p1) {            L = LL;        }        else            R = RR;    }    return (L+R)/2.0;}int main () {    //freopen ("in", "r", stdin);    while (cin >> x >> y >> l >> d) {        if (d > x || d > y) {            printf ("no\n");            continue;        }        double ans = solve ();        if (f (ans) <= eps) {            printf ("yes\n");        }        else            printf ("no\n");    }    return 0;}


0 0
原创粉丝点击