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;
}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/veget_chicken/article/details/52347088
文章标签: 数学
个人分类: 数学
相关热词: problem
上一篇&quot;Or&quot; Game
下一篇Making a String
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭