C. Mixing Water

鏈接:https://codeforces.ml/contest/1359/problem/C

There are two infinite sources of water:

  • hot water of temperature hh;
  • cold water of temperature cc (c<hc<h).

You perform the following procedure of alternating moves:

  1. take one cup of the hot water and pour it into an infinitely deep barrel;
  2. take one cup of the cold water and pour it into an infinitely deep barrel;
  3. take one cup of the hot water ……
  4. and so on ……

Note that you always start with the cup of hot water.

The barrel is initially empty. You have to pour at least one cup into the barrel. The water temperature in the barrel is an average of the temperatures of the poured cups.

You want to achieve a temperature as close as possible to tt. So if the temperature in the barrel is tbtb, then the absolute difference of tbtb and tt (|tb−t||tb−t|) should be as small as possible.

How many cups should you pour into the barrel, so that the temperature in it is as close as possible to tt? If there are multiple answers with the minimum absolute difference, then print the smallest of them.

Input

The first line contains a single integer TT (1≤T≤3⋅1041≤T≤3⋅104) — the number of testcases.

Each of the next TT lines contains three integers hh, cc and tt (1≤c<h≤1061≤c<h≤106; c≤t≤hc≤t≤h) — the temperature of the hot water, the temperature of the cold water and the desired temperature in the barrel.

Output

For each testcase print a single positive integer — the minimum number of cups required to be poured into the barrel to achieve the closest temperature to tt.

Example

input

Copy

3
30 10 20
41 15 30
18 13 18

output

Copy

2
7
1

Note

In the first testcase the temperature after 22 poured cups: 11 hot and 11 cold is exactly 2020. So that is the closest we can achieve.

In the second testcase the temperature after 77 poured cups: 44 hot and 33 cold is about 29.85729.857. Pouring more water won't get us closer to tt than that.

In the third testcase the temperature after 11 poured cup: 11 hot is 1818. That's exactly equal to tt.

代碼:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lb long double
#define INF 0x3f3f3f3f
#define maxn 200010
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define gep(i,x,y) for(int i=x;i>=y;i--)
ll n,T,m,h,c,k,t,x,y,max1,b,s;
char a[101][1001];
int main()
{
	cin>>T;
	while(T--)
	{
		cin>>h>>c>>t;
		s=h;
		double min1=1e9+7;
		if(t==s)
		cout<<1<<endl;
		else
		{
			min1=abs(t-h);
			k=1;
			s+=c;
			double k1=s*1.0/2;
			if(min1>abs(t-k1))
			{
				min1=abs(t-k1);
				k=2;
			}
			if(t<=k1)
			{
				cout<<k<<endl;
			}
			else
			{
				ll l=1,r=1e6,mid;
				while(l<=r)
				{
					mid=(l+r)/2;
					s=mid*(h+c)+h;
					double k2=s*1.0/(mid*2+1);
					if(k2<t)
					{
						if(min1>abs(k2-t))
						{
							min1=abs(k2-t);
							k=mid*2+1;
						}
						r=mid-1;
					}
					else
					{
						if(min1>abs(k2-t))
						{
							min1=abs(k2-t);
							k=mid*2+1;
						}
						l=mid+1;
					}
				}
				cout<<k<<endl;
			}
			
		}
	}
}
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章