# 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.

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

• 本文已收录于以下专栏：

举报原因： 您举报文章：A Problem about Polyline 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)