zoukankan      html  css  js  c++  java
  • 「SHOI2012」信用卡凸包

    传送门

    每一段圆弧直接求显然是不太好做的,但我们不难发现所有圆弧长度之和就是一个半径为 (r) 的圆的周长,那我们考虑只算直线段部分。

    线段有两种:一种直接贴着矩形的边的,一种切于两个矩形圆角的。

    第一种线段很好求,对于第二种线段画个图发现它其实就是这两段圆弧圆心的连线长度。

    那么我们就直接把所有圆角矩形里的四个圆弧的圆心抠出来求个凸包周长,最后再把圆的周长加进去就好了。

    参考代码:

    #include <algorithm>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    
    const int _ = 1e5 + 5;
    const double pi = acos(-1.0);
    
    int N; double x, y, d, a, b, r, ans = 0;
    int n, top; struct node { double x, y; } t[_], stk[_];
    int cmp(node a, node b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
    
    node operator - (node a, node b) { return (node) { a.x - b.x, a.y - b.y }; }
    
    double operator * (node a, node b) { return a.x * b.y - b.x * a.y; }
    
    double dist(node a, node b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
    
    double X(double x, double y, double d) { return x * cos(d) - y * sin(d); }
    
    double Y(double x, double y, double d) { return x * sin(d) + y * cos(d); }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("cpp.in", "r", stdin), freopen("cpp.out", "w", stdout);
    #endif
        scanf("%d %lf %lf %lf", &N, &b, &a, &r);
        a = a / 2 - r, b = b / 2 - r;
        for (int i = 1; i <= N; ++i) {
            scanf("%lf %lf %lf", &x, &y, &d);
            t[++n] = (node) { x + X(a, b, d), y + Y(a, b, d) };
            t[++n] = (node) { x + X(a, -b, d), y + Y(a, -b, d) };
            t[++n] = (node) { x + X(-a, b, d), y + Y(-a, b, d) };
            t[++n] = (node) { x + X(-a, -b, d), y + Y(-a, -b, d) };
        }
        sort(t + 1, t + n + 1, cmp);
        top = 0, stk[++top] = t[1], stk[++top] = t[2];
        for (int i = 3; i <= n; ++i) {
            while (top >= 2 && (stk[top] - stk[top - 1]) * (t[i] - stk[top - 1]) <= 0) --top;
            stk[++top] = t[i];
        }
        for (int i = 2; i <= top; ++i) ans += dist(stk[i], stk[i - 1]);
        top = 0, stk[++top] = t[1], stk[++top] = t[2];
        for (int i = 3; i <= n; ++i) {
            while (top >= 2 && (stk[top] - stk[top - 1]) * (t[i] - stk[top - 1]) >= 0) --top;
            stk[++top] = t[i];
        }
        for (int i = 2; i <= top; ++i) ans += dist(stk[i], stk[i - 1]);
        printf("%.2lf
    ", ans + 2 * pi * r);
        return 0;
    }
    
  • 相关阅读:
    web 移动端 适配
    meta
    meta设置
    时间
    CentOS下配置nginx conf/koi-win为同一文件的各类错误
    CentOS7 配置LAMP
    centos 进度条卡死
    LeetCode02:两数相加
    LeetCode01:两数之和
    单链表类,链表逆置
  • 原文地址:https://www.cnblogs.com/zsbzsb/p/13159932.html
Copyright © 2011-2022 走看看