當前位置:
首頁 >
[洛谷P3829][SHOI2012]信用卡凸包
發布時間:2025/3/17
21
豆豆
生活随笔
收集整理的這篇文章主要介紹了
[洛谷P3829][SHOI2012]信用卡凸包
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目大意:有$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; }
轉載于:https://www.cnblogs.com/Memory-of-winter/p/10361478.html
總結
以上是生活随笔為你收集整理的[洛谷P3829][SHOI2012]信用卡凸包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kubernetes中使用CronJob
- 下一篇: 网站高并发优化性能调优总结