Farthest Point

    xiaoxiao2025-03-19  14

    问题:http://hihocoder.com/contest/hiho111/problem/1

    详解:http://hihocoder.com/discuss/question/3573

    注意点:

    浮点类型的比较方式

    设定极小量eps,对于两个浮点数a,b

    逻辑关系比较方式a==babs(a-b)<epsa != babs(a-b)>epsa>ba-b>epsa>=ba-b>-eps

    实现:

    #include #include using namespace std; #define MAX 1000000 #define eps 1e-6 double x, y, r; inline int choose(int y1, int y2, double d) { if (y1 >= d && y2 <= d) return y1 - d >= d - y2 ? y1 : y2; else if (y1 >= d) return y1; else if (y2 <= d) return y2; else return MAX; } void solve() { double max, rs, d, t; int yt, m_x, m_y; cin >> x >> y >> r; rs = r * r, max = m_x = m_y = -1; for (int i = floor(x + r); i >= ceil(x - r); --i) { t = (i - x) * (i - x); d = sqrt(rs - t); yt = choose(floor(y + d), ceil(y - d), y); if (yt == MAX) continue; t += (yt - y) * (yt - y); if (t - max > eps) { max = t; m_x = i; m_y = yt; } } cout << m_x << " " << m_y << endl; } int main() { solve(); return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1297173.html
    最新回复(0)