题意:
一杯热水,一杯凉水,一杯热水,一杯凉水,一杯热水…
这样往杯子里加,找到最接近给定温度T,输出最小的加水次数
可以发现,加偶数次,即热水杯水等于凉水,它的温度是不变的始终是(h+c)/2
加奇数次,即热水杯水等于凉水+1,它的温度随着杯数增加是递减的
二分找到奇数杯的最接近温度T的,二分结果可能有误差,在上下摆动算一下最小的就行了
typedef long long ll;
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//::iterator it;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
ll c,h,T;
double get(ll m){
return (1.0*(m/2)*(h+c)+h)/m;
}
int main()
{
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
cin>>h>>c>>T;
if(h==T){
cout<<1<<endl;
continue;
}
double x=(h+c)/2.0;
double st=(h*2+c)/3.0;
ll l=1,r=1e10;
ll m;
while(l<r){
m=(l+r)/2;
if(m%2==0)m++;
//cout<<l<<" "<<r<<" "<<m<<" "<<endl;
if(get(m)<T)r=m-1;
else l=m+1;
}
if(l%2==0)l++;
//cout<<l<<endl;
ll ans=l;
double mi=get(l);
for(ll i=max(1ll,l-2);i<=l+2;i+=2){//上下摆动找最小的
//cout<<i<<" "<<get(i)<<" "<<fabs(get(i)-T)<<" "<<fabs(mi-T)<<endl;
if(fabs(get(i)-T)<fabs(mi-T)){
ans=i;
mi=get(i);
}
if(fabs(get(i)-T)==fabs(mi-T)){
ans=min(ans,i);
}
}
if(fabs(mi-T)>=fabs(x-T))ans=2,mi=x;//x是两杯的温度
cout<<ans<<endl;
}
return 0;
}
/*
1
41 15 30
1
656428 610660 653269
1
1138 4 643
*/