计算几何入门

该博客提供了计算几何相关学习资源,包含计算几何凸包的概念和建立过程、旋转卡壳知识点及宽度求解的学习链接,还给出了例题“Breaking Biscuits”,代码部分待更新。

学习链接:

计算几何凸包的概念和建立过程:https://blog.youkuaiyun.com/u013377068/article/details/80095620

旋转卡壳知识点详解:https://blog.youkuaiyun.com/qq_36172505/article/details/80228394

旋转卡壳宽度求解:https://blog.youkuaiyun.com/zhang20072844/article/details/6817734

例题:

Breaking Biscuits

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
typedef long long ll;
struct node
{
    int x;
    int y;
}p[maxn];

double callen(int x1, int y1, int x2, int y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

ll cross(int x1, int y1, int x2, int y2, int x3, int y3)
{
    return (x3 - x1) * (y3 - y2) - (y3 - y1) * (x3 - x2);
}

int main()
{
    int n;
    int i, j, k;
    double minlen = 1e18;

    cin >> n;
    for(i = 0; i < n; i++)
        cin >> p[i].x >> p[i].y;
    for(i = 0; i < n; i++)
        for(j = i; j < n; j++)
        {
            ll low, high;
            double len;

            len = callen(p[i].x, p[i].y, p[j].x, p[j].y);
            low = high = 0;
            for(k = 0; k < n; k++)
            {
                ll s = cross(p[i].x, p[i].y, p[j].x, p[j].y, p[k].x, p[k].y);
                low = min(low, s);
                high = max(high, s);
            }
            minlen = min(minlen, (high - low) / len);
        }
    printf("%.9f", minlen);

    return 0;
}

待更新。。。。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;

struct node
{
    int x, y;
}p[maxn];

line operator -(node a, node b)
{
    return line(a.x - b.y, a.y - b.x);
}

double callen(node a, node b)
{
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

ll cross(line a, line b)////
{
    return a.x * b.y - a.y * b.x;
}

bool comp(node a, node b)
{
    int crossval = cross(p[0], a, b);
    return crossval > 0 || !crossval && callen(p[0], a) < callen(p[0], b);
}

int main()
{
    int n;
    int i, j, k;

    cin >> n;
    for(i = 0; i < n; i++)
        scanf("%d%d", &p[i].x, &p[i].y);
    int t = 0;
    for(i = 1; i < n; i++)
        if(p[i].x < p[t].x || p[i].x == p[t].x && p[i].y < p[t].y)
            t = i;
    swap(p[0], p[t]);
    sort(p + 1, p + n, comp);

    int s[maxn];
    s[0] = p[0];
    int top = 0;
    for(i = 1; i < n; i++)
    {
        while(top > 0 && cross(p[top] - p[top - 1], p[top] - p[i]) >= 0)
            top--;
        s[++top] = p[i];
    }




}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值