A Problem about Polyline

链接:

题目:

There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – ....

We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.



题意:一条以x为比例因子渐增的折线,给一个点判断该点能否出现在该折线上,以及如果能,求最小的x

分析:数学题,主要是判断之后,找到点左右的两个折线与x轴相交的点(其实是两种情况,在折线的上升沿和下降沿),然后分别作为最小情况求出x的值,比较后留下最小的。

题解:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <cmath>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <deque>
#include <list>
#include <set>
#include <utility>
#define rt return 0
#define fr freopen("in.txt","r",stdin)
#define fw freopen("out.txt","w",stdin)
using namespace std;



double wr(int a, int b)
{
	int m = a / (2 * b);
	return (double)a / (double)(2 * m);
}

int main()
{
	//fr;
	int a, b;
	cin >> a >> b;
	if (a<b)
	{
		cout << -1 << endl;
		rt;
	}
	int t = a - b;
	int p = a + b;
	double ans = min(wr(p, b), wr(t, b));
	printf("%.10lf\n", ans);
	rt;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值