链接:
题目:
题意:一条以x为比例因子渐增的折线,给一个点判断该点能否出现在该折线上,以及如果能,求最小的x
分析:数学题,主要是判断之后,找到点左右的两个折线与x轴相交的点(其实是两种情况,在折线的上升沿和下降沿),然后分别作为最小情况求出x的值,比较后留下最小的。
题解:
题目:
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;
}