关闭

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

117人阅读 评论(0) 收藏 举报

【题目链接】

好像是比较经典的题了。

第一次在考场上写三分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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:106760次
    • 积分:4820
    • 等级:
    • 排名:第6162名
    • 原创:392篇
    • 转载:0篇
    • 译文:0篇
    • 评论:48条
    膜拜神犇
    最新评论