P3829 [SHOI2012] 信用卡凸包 - 洛谷
给出 \(n\) 个圆角矩形, 问这 \(n\) 个矩形构成的凸包的周长.
代码
| C++ |
|---|
| { 计算几何基础 }
{ 二维凸包 }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
Tdouble a, b, r;
cin >> n >> a >> b >> r;
a -= 2 * r;
b -= 2 * r;
Tdouble L = sqrt(a * a + b * b) / 2;
Tdouble phi = atan(a / b);
vector<Point> c;
for (int i = 0 ; i < n ; i++) {
Tdouble x, y, theta;
cin >> x >> y >> theta;
{
Tdouble dx = cos(theta + phi) * L;
Tdouble dy = sin(theta + phi) * L;
c.emplace_back(x + dx, y + dy);
c.emplace_back(x - dx, y - dy);
}
{
Tdouble dx = cos(theta - phi) * L;
Tdouble dy = sin(theta - phi) * L;
c.emplace_back(x + dx, y + dy);
c.emplace_back(x - dx, y - dy);
}
}
auto res = ConvexHull2D(c);
Tdouble ans = 0;
int len = res.size();
for (int i = 0 ; i < len - 1 ; i++) {
ans += distance(res[i], res[i + 1]);
}
cout << fixed << setprecision(2) << ans + 2 * PI * r << "\n";
return 0;
}
|