bzoj1038: [ZJOI2008]瞭望塔

半平面交求最低点,较裸

此题答案非常大,用INFwa了很久

const DB eps = 0.000001;
const int N = 310;
int n, m;

inline int Equal(DB a, DB b) {
	if(fabs(a - b) < eps) return 0;
	return a < b ? -1 : 1;
}

struct Point {
	DB x, y;
	Point(DB _x, DB _y) : x(_x), y(_y) {}
	Point() {}
} P[N];
struct Line {
	DB a, b;
	Line() {}
	Line(DB _a, DB _b) : a(_a), b(_b) {}
	inline bool operator <(const Line &L)const {
		int T = Equal(a, L.a);
		if(T) return T == -1;
		return b > L.b;
	}
	inline bool operator ==(const Line &L)const { return Equal(a, L.a) == 0; }
	inline DB Caln(DB x) { return a * x + b; }
} Dat[N];

inline void Input() {
	scanf("%d", &n);
	Rep(i, n) scanf("%lf", &P[i].x);
	Rep(i, n) scanf("%lf", &P[i].y);
}

inline Line Get(Point a, Point b) {
	Line ret;
	ret.a = (b.y - a.y) / (b.x - a.x); ret.b = a.y - a.x * ret.a;
	return ret;
}
inline DB Ox(Line L1, Line L2) {
	return -(L1.b - L2.b) / (L1.a - L2.a);
}
inline DB Caln(DB x, Line Up, Line Down) {
	return Up.Caln(x) - Down.Caln(x);
}
inline void Solve() {
	Rep(i, n - 1) Dat[i] = Get(P[i], P[i+1]);
	
	m = n - 1;
	sort(Dat, Dat + m);
	m = unique(Dat, Dat + m) - Dat;
	int p = 0;
	Rep(i, m) {
		while(p >= 2 && Equal(Ox(Dat[p - 2], Dat[p - 1]), Ox(Dat[p- 1], Dat[i])) >= 0) p--;
		Dat[p++] = Dat[i];
	}
	m=p;
	
	int L = 0, R = 0;
	DB Ans = 1e30; //不能用1e9
	#define Update(x) (Ans = min(Ans, Caln(x, Dat[R], Get(P[L], P[L+1]))))
	while(L + 1 < n && R < m) {
		DB l = R ? Ox(Dat[R - 1], Dat[R]) : -INF, r = R + 1 < m ? Ox(Dat[R], Dat[R + 1]) : INF;
		if(l > P[L + 1].x) {
			L++;
			continue;
		}
		if(r < P[L].x) {
			R++;
			continue;
		}
		Update(max(l, P[L].x)), Update(min(P[L+1].x, r));
		if(r < P[L + 1].x) R++;
		else L++;
	}
	if(n == 1) Ans = 0;
	if(Equal(Ans, 0) == 0) Ans = 0;
	printf("%0.3lf\n", Ans);
}

int main() {
	Input();
	Solve();
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值