Problem-1005

概述:west先生要将车开过一个拐角,现在给出拐角两侧道路的长度和汽车的长度和宽度,求车是否能过去。

思路:车能过去,就是车的左侧紧贴直角点,右侧紧贴道路下方的店,使用函数得到:F(a)=lcosa-(x-w/cosa)/tana,是一个单峰函数,所以可以使用三分法。

感想:知道是三分,题意不难理解,难的是那个方程的解,写出来题就简单了。

#include<iostream>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<stdio.h>
#include<cstring>
#define PI 3.14159
const double dps = 1e-4;
double x, y, l, w;
double calution(double a)
{
	return l*cos(a) + (w - x*cos(a)) / sin(a);
}
double ternary_search(double l, double r) 
{
	double ll, rr;
	while (r - l>dps) 
	{
		ll = (2 * l + r) / 3;
		rr = (2 * r + l) / 3;
		if (calution(ll)>calution(rr))
			r = rr;
		else
			l = ll;
	}
	return r;
}


using namespace std;

int main()
{
	ifstream cin("in.txt");
	while (cin >> x >> y >> l >> w)
	{
		double l = 0, r = PI / 2;
		double temp = ternary_search(l, r);
		if (calution(temp) < y)
			puts("yes");
		else puts("no");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值