【BZOJ1857】[Scoi2010]传送带【三分套三分】

【题目链接】

好像是比较经典的题了。

第一次在考场上写三分orz。

/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef double DB;

const DB eps = 1e-6;

struct po {
	DB x, y;
} A, B, C, D, AB, DC;

DB P, Q, R, lenAB, lenCD;

inline int iread() {
	int f = 1, x = 0; char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	return  f * x;
}

inline DB dis(po a, po b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

inline bool dcmp(po a, po b) {
	return fabs(a.x - b.x) < eps && fabs(a.y - b.y) < eps;
}

inline DB getres(po X) {
	if(dcmp(C, D)) return dis(X, D) / R;
	po l = D, r = C;
	while(!dcmp(l, r)) {
		DB len = dis(l, r) / 3.0;
		po p1 = (po){l.x + DC.x * len, l.y + DC.y * len};
		po p2 = (po){l.x + DC.x * len * 2, l.y + DC.y * len * 2};
		DB res1 = dis(X, p1) / R + dis(p1, D) / Q;
		DB res2 = dis(X, p2) / R + dis(p2, D) / Q;
		if(res1 < res2) r = p2;
		else l = p1;
	}
	return dis(X, l) / R + dis(l, D) / Q;
}

int main() {
	A.x = iread(); A.y = iread(); B.x = iread(); B.y = iread();
	C.x = iread(); C.y = iread(); D.x = iread(); D.y = iread();
	P = iread(); Q = iread(); R = iread();

	lenAB = dis(A, B); lenCD = dis(C, D);
	AB = (po){(B.x - A.x) / lenAB, (B.y - A.y) / lenAB};
	DC = (po){(C.x - D.x) / lenCD, (C.y - D.y) / lenCD};

	if(dcmp(A, B)) {
		if(dcmp(C, D)) printf("%.2f\n", dis(A, D) / R);
		else printf("%.2f\n", getres(A));
		return 0;
	}

	DB ans;
	po l = A, r = B;
	while(!dcmp(l, r)) {
		DB len = dis(l, r) / 3.0;
		po p1 = (po){l.x + AB.x * len, l.y + AB.y * len};
		po p2 = (po){l.x + AB.x * len * 2, l.y + AB.y * len * 2};
		DB res1 = dis(A, p1) / P + getres(p1);
		DB res2 = dis(A, p2) / P + getres(p2);
		if(res1 < res2) ans = res1, r = p2;
		else ans = res2, l = p1;
	}

	printf("%.2f\n", ans);
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值