[BZOJ]2829 信用卡凸包 凸包

2829: 信用卡凸包

Time Limit: 10 Sec   Memory Limit: 128 MBSec   Special Judge
Submit: 441   Solved: 212
[ Submit][ Status][ Discuss]

Description

Input

Output

Sample Input

2
6.0 2.0 0.0
0.0 0.0 0.0
2.0 -2.0 1.5707963268

Sample Output

21.66

HINT


本样例中的2张信用卡的轮廓在上图中用实线标出,如果视1.5707963268为

Pi/2(pi为圆周率),则其凸包的周长为16+4*sqrt(2)

Source

[ Submit][ Status][ Discuss]


HOME Back

  今天下午儿子zjc分享了这道题~ 圆弧部分加起来是一个圆很显然? 感觉YY一下各个圆弧角度刚好加起来360度, 凑一个圆周长. 那么就只需要定信用卡四个圆心为点, 求个凸包, 然后求相邻距离之和, 最后加上一个圆的周长即可. 注意向量的旋转可以自己推一下, 还是很好推的.

#include<bits/stdc++.h>
#define pp pop_back
#define pb push_back
using namespace std;
const double pi = acos(-1.0);
int n, m;
double ans;
struct Vector {
	double x, y;
	Vector() {}
	Vector(double x, double y) : x(x), y(y) {}
	inline friend bool operator < (const Vector &r, const Vector &s) {
		return r.x < s.x || (r.x == s.x && r.y < s.y);
	}
	inline friend Vector operator + (const Vector &r, const Vector &s) {
		return Vector(r.x + s.x, r.y + s.y); 
	}
	inline friend Vector operator - (const Vector &r, const Vector &s) {
		return Vector(r.x - s.x, r.y - s.y);
	}
};
typedef Vector Point;
inline double cross(const Vector &r, const Vector &s) {
	return r.x * s.y - r.y * s.x;
}
inline double length(const Vector &r) {
	return sqrt(r.x * r.x + r.y * r.y);
}
inline bool onleft(const Point &A, const Point &B, const Point &C) {
	return cross(B - A, C - A) > 0;
}
inline Vector rotate(const Vector &r, double rad) {
	return Vector(r.x * cos(rad) - r.y * sin(rad), r.x * sin(rad) + r.y * cos(rad));
}
vector<Point> pts;
vector<Point> cvx;

inline void Convex_Hull() {
	int nm = pts.size();
	sort(pts.begin(), pts.end());
	for (int i = 0; i < nm; ++ i) {
		while(n > 1 && onleft(cvx[n - 2], cvx[n - 1], pts[i])) cvx.pp(), n --;
		cvx.pb(pts[i]), n ++;
	}
	int k = n;
	for (int i = nm - 2; ~i; --i) {
		while(n > k && onleft(cvx[n - 2], cvx[n - 1], pts[i])) cvx.pp(), n --;
		cvx.pb(pts[i]), n ++;
	}
	if (nm > 1) -- n, cvx.pp();
}
int main() {
	Vector v;
	Point P, Q;
	double a, b, r;
	scanf("%d", &m);
	scanf("%lf%lf%lf", &a, &b, &r);
	a -= 2 * r, b -= 2 * r;
	for (int i = 1; i <= m; ++ i) {
		double x, y, rad;
		scanf("%lf%lf%lf", &x, &y, &rad);
		P = Point(x, y);
		Q = Point(x - b / 2, y + a / 2), v = rotate(Q - P, rad), pts.pb(P + v);
		Q = Point(x - b / 2, y - a / 2), v = rotate(Q - P, rad), pts.pb(P + v);
		Q = Point(x + b / 2, y + a / 2), v = rotate(Q - P, rad), pts.pb(P + v);
		Q = Point(x + b / 2, y - a / 2), v = rotate(Q - P, rad), pts.pb(P + v);
	}
	Convex_Hull();
	for (int i = 0; i < n; ++ i)
		ans += length(cvx[(i + 1) % n] - cvx[i]);
	printf("%.2f\n", ans + 2 * pi * r);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值