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: 6ms
Memory: 1716kB
Author: 2017212212237
In contest: 1289

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define ll long long

const int maxn = 1e2 + 10;
const int INF = 0x3f3f3f3f;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int flag = 0;
        double a,b,sum = 0;
        int x;
        scanf("%lf %lf %d",&a,&b,&x);
        while(sum < x)
        {
            int k = ceil(a/b - 1);
            double dx = (a - b * k) / (2 * k + 1);
            dx = min(dx,x - sum);
            a -= dx * (2 * k + 1);
            sum += dx;
            if(a < b && sum + b < x)
            {
                flag = 1;
                break;
            }
        }
        if(flag)
            puts("-1");
        else
            printf("%.5f\n",a);
    }
}