题目大意:有$n$张一模一样的信用卡,每个角进行了圆滑处理,问这些卡组成的“凸包”的周长

题解:发现是圆滑处理的圆心围成的凸包加上一个圆周即可

卡点:输入长宽弄反,然后以为是卡精

C++ Code:

#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#define maxn 10010
const double Pi = acosl(-1); struct Point {
long double x, y;
Point() { }
Point(long double __x, long double __y) : x(__x), y(__y) { } inline long double operator ^ (const Point &rhs) const {
return x * rhs.y - y * rhs.x;
}
inline Point operator + (const Point &rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
inline Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
inline Point rotate(long double theta) {
const long double Sin = sinl(theta), Cos = cosl(theta);
return Point(x * Cos - y * Sin, x * Sin + y * Cos);
}
} s[maxn << 2], O, v[maxn << 2];
inline long double abs2(const Point &x) { return x.x * x.x + x.y * x.y; }
inline long double dis(const Point &lhs, const Point &rhs) { return sqrtl(abs2(lhs - rhs)); }
inline long double det(const Point &O, const Point &lhs, const Point &rhs) {
return (lhs - O) ^ (rhs - O);
}
inline bool cmp(const Point &x, const Point &y) {
static Point X, Y; X = x - O, Y = y - O;
static long double tmp; tmp = X ^ Y;
return (tmp > 0) || (tmp == 0 && abs2(X) < abs2(Y));
} int n, tot;
long double ans, A, B, R;
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
std::cin >> n >> A >> B >> R; ans = 2 * R * Pi;
A /= 2, B /= 2, A -= R, B -= R;
for (int i = 0; i < n; ++i) {
static long double x, y, theta;
std::cin >> x >> y >> theta;
const Point t1 = Point(B, A).rotate(theta), t2 = Point(B, -A).rotate(theta), O(x, y);
s[tot++] = O - t1, s[tot++] = O + t1;
s[tot++] = O - t2, s[tot++] = O + t2;
}
int miny = 0;
for (int i = 0; i < tot; ++i)
if (s[i].y < s[miny].y || (s[i].y == s[miny].y && s[i].x < s[miny].x)) miny = i;
std::swap(s[0], s[miny]); O = s[0];
std::sort(s + 1, s + tot, cmp);
n = tot, tot = 3;
v[0] = s[0], v[1] = s[1], v[2] = s[2];
for (int i = 3; i < n; ++i) {
Point *a = v + tot - 2, *b = v + tot - 1;
while (tot > 2 && det(*a, *b, s[i]) <= 0) {
--tot, --a, --b;
}
v[tot++] = s[i];
}
for (int i = 1; i < tot; ++i) ans += dis(v[i - 1], v[i]);
ans += dis(v[0], v[tot - 1]);
std::cout << std::fixed << std::setprecision(2) << ans << '\n';
return 0;
}

  

[洛谷P3829][SHOI2012]信用卡凸包的更多相关文章

  1. luogu P3829 [SHOI2012]信用卡凸包 凸包 点的旋转

    LINK:信用卡凸包 当 R==0的时候显然是一个点的旋转 之后再求凸包即可. 这里先说点如何旋转 如果是根据原点旋转的话 经过一个繁杂的推导可以得到一个矩阵. [cosw,-sinw] [sinw, ...

  2. P3829 [SHOI2012]信用卡凸包

    思路 注意到结果就是每个信用卡边上的四个圆心的凸包周长+一个圆的周长 然后就好做了 注意平行时把距离小的排在前面,栈中至少要有1个元素(top>1),凸包中如果存在叉积为0的点也要pop,否则可 ...

  3. 【BZOJ2829】[SHOI2012]信用卡凸包(凸包)

    [BZOJ2829][SHOI2012]信用卡凸包(凸包) 题面 BZOJ 洛谷 题解 既然圆角的半径都是一样的,而凸包的内角和恰好为\(360°\),所以只需要把圆角的圆心弄下来跑一个凸包,再额外加 ...

  4. [SHOI2012]信用卡凸包(凸包+直觉)

    这个题还是比较有趣. 小心发现,大胆猜想,不用证明! 我们发现所谓的信用卡凸包上弧的长度总和就是圆的周长! 然后再加上每个长宽都减去圆的直径之后的长方形的凸包周长即可! #include<ios ...

  5. Luogu-3829 [SHOI2012]信用卡凸包

    这道题的转化很巧妙,可以把信用卡四个角的圆心看做平面上的点来做凸包,\(ans\)就是凸包周长加上一个圆的周长 // luogu-judger-enable-o2 #include<cmath& ...

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

    /* 考验观察法?? 可以发现最终答案等于所有作为圆心的点求出凸包的周长加上一个圆的周长 向量旋转 (x1, y1) 相较于 (x2, y2) 旋转角c 答案是 (dtx * cosc - dty * ...

  7. 洛谷——P3833 [SHOI2012]魔法树

    P3833 [SHOI2012]魔法树 题目背景 SHOI2012 D2T3 题目描述 Harry Potter 新学了一种魔法:可以让改变树上的果子个数.满心欢喜的他找到了一个巨大的果树,来试验他的 ...

  8. 洛谷3833 [SHOI2012]魔法树

    SHOI2012 D2T3 题目描述 Harry Potter 新学了一种魔法:可以让改变树上的果子个数.满心欢喜的他找到了一个巨大的果树,来试验他的新法术. 这棵果树共有N个节点,其中节点0是根节点 ...

  9. 洛谷 P3833 [SHOI2012]魔法树

    题目背景 SHOI2012 D2T3 题目描述 Harry Potter 新学了一种魔法:可以让改变树上的果子个数.满心欢喜的他找到了一个巨大的果树,来试验他的新法术. 这棵果树共有N个节点,其中节点 ...

随机推荐

  1. day01_概念

    1 网络分类: 1 按照范围: - 局域网:范围很小的网络,如一间办公室,一个公司 - 城域网:大致城市范围内的网络,半径几公里到几十公里 - 广域网:比城域网范围更大的 2 网络衡量标准 1 传输速 ...

  2. 《python 经典实例》 分享 pdf下载

    链接:https://pan.baidu.com/s/1FzSsBfynqx5ll_OpcZGDHg提取码:ykgk

  3. 《数据结构与算法图解》 分享 pdf下载

    链接:https://pan.baidu.com/s/1gOMlwU5ucHYDVazvVMk2uw提取码:bk5x

  4. 教你如何编写、保存与运行 Python 程序

    第一步 接下来我们将看见如何在 Python 中运行一个传统的“Hello World”程序.Python教程本章将会教你如何编写.保存与运行 Python 程序. 通过 Python 来运行的你的程 ...

  5. python的eval和json.loads(),json.dumps()

    eval() 将字符串当成一个表达式去执行,可以想象成一个去字符串然后执行的操作. In [1]: s = '3*8' In [2]: eval(s) Out[2]: 24 eval()和json.l ...

  6. kubernetes集群部署mysql 8.0

    参考:https://blog.csdn.net/sealir/article/details/81177747?utm_source=blogxgwz1 集群内安装mysql并添加相应存储(PVC) ...

  7. 服务端模版注入漏洞检测payload整理

    服务端模版注入漏洞产生的根源是将用户输入的数据被模版引擎解析渲染可能导致代码执行漏洞 下表涵盖了java,php,python,javascript语言中可能使用到的模版引擎,如果网站存在服务端模版注 ...

  8. SQL面经汇总

    转载链接:https://www.nowcoder.com/discuss/95812 目前的打算是还要写一个假设检验的汇总和机器学习的汇总. 之前写的概率论汇总: https://www.nowco ...

  9. MyForm_参考django的Form组建

    fork wupeiqi:https://github.com/fat39/Tyrion 组件说明:https://www.cnblogs.com/wupeiqi/p/5938916.html

  10. CentOS6安装与运行R脚本

    http://blog.csdn.net/bdchome/article/details/47811763