Start: Jun, 28, 2019 13:00:00
2019年度暑期短学期第四天-助教场
End: Jun, 30, 2019 23:59:00
Time elapsed:
Time remaining:

Problem_ID: F
Result: Accepted
Time: 20ms
Memory: 1756kB
Author: 2017212212167
In contest: 1289

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;

double a, b, x;

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> a >> b >> x;
		if (a < x)
		{
			cout << -1 << endl;
			continue;
		}
		int k = ceil(a / b);
		double now = 0;
		while (now < x)
		{
			int cnt = 2 * k - 1;
			double tmp = (a - b * (k - 1)) / cnt;
			tmp = min(x - now, tmp);
			now += tmp;
			a -= cnt*tmp;
			if (x - now > b&&a < b)
			{
				a = -1;
				break;
			}
			k--;
		}
		if (a < 0)
			printf("-1\n");
		else
			printf("%.5lf\n", a);
	}
	return 0;
}