UVALive 3890 Most Distant Point from the Sea(凸包最大内接圆)

本文介绍了一种求解凸多边形中最大内切圆半径的方法,通过半平面交技术和二分查找算法实现。该方法首先确定凸包上的每条边对应的半平面,并沿垂直单位法向量平移预设距离,然后检查平移后的半平面交集是否为空来逐步逼近最大内切圆的半径。

一个n个点的凸多边形,求多边形中离多边形边界最远的距离。实际上就是求凸包最大内接圆的半径。

利用半平面交求解,每次二分枚举半径d,然后将凸包每条边所代表的半平面沿其垂直单位法向量平移d,看所有平移后的半平面的交集是否为空。

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<bitset>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define eps 1e-10
using namespace std;

struct Point
{
    double x, y;
    Point (double x=0, double y=0):x(x), y(y) {}
};
typedef Point Vector;

Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); }

bool operator < (const Point& a, const Point& b)
{
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}

int dcmp(double x)
{
    if(fabs(x) < eps) return 0;
    return x < 0 ? -1 : 1;
}

bool operator == (const Point& a, const Point& b)
{
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}

double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; }
double Length(Vector A) { return sqrt(Dot(A, A)); }
double Angel(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
double Area2(Vector A, Vector B, Vector C) { return Cross(B-A, C-A); }
Vector Normal(Vector a) //a向量的垂直法向量
{
     return Vector(-a.y/Length(a), a.x/Length(a));
}

struct Line
{
    Point p;
    Vector v;
    double ang;
    Line() {}
    Line(Point p, Vector v): p(p), v(v) {ang = atan2(v.y, v.x); }
    bool operator < (const Line& L) const
    {
        return ang < L.ang;
    }
};

//点p在半平面的左边
bool onLeft(Line L, Point p) { return Cross(L.v, p-L.p) > 0; }
//直线交点
Point GetIntersection(Line a, Line b)
{
    Vector u = a.p-b.p;
    double t = Cross(b.v, u) / Cross(a.v, b.v);
    return a.p + a.v*t;
}

const int maxn = 200;
Point p[maxn], poly[maxn];
Line L[maxn];
Vector v[maxn], v2[maxn];
int n;

//半平面交
Point pp[maxn];
Line qq[maxn];
int HalfplaneIntersection(Line* L, int n, Point* poly)
{
    sort(L, L+n);
    int first, last;

    qq[first=last=0] = L[0];
    FF(i, 1, n)
    {
        while(first < last && !onLeft(L[i], pp[last-1])) last--;
        while(first < last && !onLeft(L[i], pp[first])) first++;
        qq[++last] = L[i];
        if(fabs(Cross(qq[last].v, qq[last-1].v)) < eps)
        {
            last--;
            if(onLeft(qq[last], L[i].p)) qq[last] = L[i];
        }
        if(first < last) pp[last-1] = GetIntersection(qq[last-1], qq[last]);
    }
    while(first < last && !onLeft(qq[first], pp[last-1])) last--;
    if(last-first <= 1) return 0;
    pp[last] = GetIntersection(qq[last], qq[first]);

    int m = 0;
    FF(i, first, last+1) poly[m++] = pp[i];
    return m;
}


int main()
{
    while(scanf("%d", &n), n)
    {
        REP(i, n) scanf("%lf%lf", &p[i].x, &p[i].y);
        REP(i, n)
        {
            v[i] = p[(i+1)%n]-p[i];
            v2[i] = Normal(v[i]);
        }
        double l=0, r=20000, mid;
        while(r - l > eps)
        {
            mid = (l+r) / 2.0;
            REP(i, n) L[i] = Line(p[i]+v2[i]*mid, v[i]);
            int m = HalfplaneIntersection(L, n, poly);
            if(!m) r=mid; else l=mid;
        }
        printf("%.6f\n", l);
    }
    return 0;
}


<think>好的,用户想了解在编程或技术背景下“distant”相关的概念或用法。首先,我需要回忆一下在计算机科学和信息技术中常见的包含“distant”的术语或概念。可能的方面包括网络通信中的距离、分布式系统、远程操作相关的技术,或者算法中的距离度量等。 首先想到的是“远程过程调用”(Remote Procedure Call, RPC),这里的“远程”对应distant,指调用不同地址空间(通常在不同机器上)的过程或函数。另外,“分布式计算”(Distributed Computing)也涉及多台计算机协同工作,可能分布在不同的地理位置,这也是distant的一种体现。 着是网络方面的术语,比如“延迟”(Latency),即数据从一点传输到另一点的时间,这可能涉及到地理距离的影响,比如远距离通信中的延迟问题。还有“地理分布式系统”(Geographically Distributed Systems),例如内容分发网络(CDN),通过将服务器部署在全球各地来减少用户访问的延迟。 在数据结构和算法中,可能有“编辑距离”(Edit Distance)或“汉明距离”(Hamming Distance),这些用于衡量两个字符串之间的差异程度。虽然这里的distance不一定指物理距离,但属于技术中的距离概念。 此外,还有“远程终端”(Remote Terminal)或“远程桌面”(Remote Desktop),这些技术允许用户访问和控制位于远端的计算机,属于distant的应用场景。 需要确认这些术语的正确性,例如RPC确实涉及远程调用,分布式系统的定义是否符合用户需求。同时,考虑用户可能的深层需求,比如他们是否在寻找特定的技术实现,或者想了解相关概念的应用场景。还要注意用户提供的引用中的“module”和“protocol implementation”,可能引导到模块化或协议相关的远程通信技术。 最后,要确保回答的结构清晰,涵盖不同技术领域中的distant应用,并生成相关问题,帮助用户进一步探索。同时,检查是否有遗漏的重要概念,如物联网中的远程传感器、云计算中的远程服务等,确保覆盖全面。</think>在编程或技术语境中,“distant”通常与远程通信、分布式系统或空间/逻辑距离相关的概念相关。以下是几个关键方向: ### 1. **远程过程调用(RPC)** - 允许程序调用另一个地址空间(通常是另一台机器)的函数或方法,例如 gRPC[^1]。其核心是隐藏网络通信细节,使远程调用像本地调用一样。 - 示例代码片段: ```python # 使用 gRPC 的简单客户端调用 import grpc channel = grpc.insecure_channel('localhost:50051') stub = helloworld_pb2_grpc.GreeterStub(channel) response = stub.SayHello(helloworld_pb2.HelloRequest(name='Alice')) ``` ### 2. **分布式系统(Distributed Systems)** - 系统组件分布在多个物理或逻辑节点上,通过消息传递协作,例如: - **分布式数据库**:如 Cassandra,数据分片存储在不同节点。 - **区块链**:节点通过共识算法达成一致性。 ### 3. **网络延迟与地理距离** - 远距离通信需处理信号传播延迟(如跨洋光缆延迟约 60ms/1000km),影响协议设计(如 TCP 拥塞控制)。 ### 4. **距离度量算法** - **编辑距离(Edit Distance)**:衡量字符串差异,用于拼写检查。 $$ \text{edit\_distance}(s, t) = \min\{ \text{插入}, \text{删除}, \text{替换} \} $$ - **欧氏距离(Euclidean Distance)**:用于机器学习聚类(如 K-means): $$ d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum_{i=1}^n (p_i - q_i)^2} $$ ### 5. **远程设备控制** - 如 IoT 中通过 MQTT 协议控制远距离传感器: ```python import paho.mqtt.client as mqtt client = mqtt.Client() client.connect("broker.hivemq.com", 1883) client.publish("sensor/temperature", "25°C") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值