[SHOI2012]信用卡凸包(计算几何)

/*
考验观察法?? 

可以发现最终答案等于所有作为圆心的点求出凸包的周长加上一个圆的周长 
向量旋转

(x1, y1) 相较于 (x2, y2) 旋转角c 答案是

(dtx * cosc - dty * sinc + x2, dty * cosc + dtx * sinc + y2) 

貌似我的凸包也不鲁棒耶 

*/


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath> 
#include<queue>
#define ll long long 
#define M 400010
#define mmp make_pair
using namespace std;
int read()
{
    int nm = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
    return nm * f;
}
const double pi = acos(-1), eps = 1e-12;
struct Vec
{
    double x, y;
}pt[M];
double operator * (const Vec &a, const Vec &b)
{
    return a.x * b.y - a.y * b.x;
}

Vec operator + (Vec a, Vec b)
{
    return Vec{a.x + b.x, a.y + b.y};
}

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

double cross(Vec a, Vec b, Vec c)
{
    return (a - c) * (b - c); 
}

bool cmp1(Vec a, Vec b)
{
    return a.y == b.y ? a.x < b.x : a.y < b.y;
}

bool cmp(Vec a, Vec b)
{
    return cross(a, b, pt[1]) >= 0;
}

Vec rotate(Vec a, double p)
{
    return Vec{a.x * cos(p) - a.y * sin(p), a.y * cos(p) + a.x * sin(p)};
}

double diss(Vec a, Vec b)
{
    double x = a.x - b.x, y = a.y - b.y;
    return sqrt(x * x + y * y);
}

double r, h, l, a, b, ap;
int n, tp, sta[M]; 





int main()
{
    n = read();
    scanf("%lf%lf%lf", &l, &h, &r);
    h = (h - r * 2) / 2.0, l = (l - r * 2) / 2.0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%lf%lf%lf", &a, &b, &ap);
        pt[i] = rotate(Vec{h, l}, ap) + Vec{a, b};
        pt[i + 2 * n] = rotate(Vec{-h, l}, ap) + Vec{a, b};
        pt[i + 3 * n] = rotate(Vec{h, -l}, ap) + Vec{a, b};
        pt[i + n] = rotate(Vec{-h, -l}, ap) + Vec{a, b};
    }
    n *= 4;
    sort(pt + 1, pt + n + 1, cmp1);
    sta[++tp] = 1;
    sort(pt + 2, pt + n + 1, cmp);
    sta[++tp] = 2;
    sta[++tp] = 3;
    for(int i = 4; i <= n; i++)
    {
        while(tp > 1 && cross(pt[i], pt[sta[tp]], pt[sta[tp - 1]]) >= 0) tp--;
        sta[++tp] = i;
    }
    double ans = 0;
    for(int i = 1; i < tp; i++) ans += diss(pt[sta[i]], pt[sta[i + 1]]);
    ans += diss(pt[sta[1]], pt[sta[tp]]);
    ans += r * pi * 2; 
    printf("%.2lf\n", ans);
    return 0;
}

转载于:https://www.cnblogs.com/luoyibujue/p/10679581.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值