解析:
因为每次先加热水,再加凉水,所以温度的范围肯定在 [ ( h+c ) / 2 , h ]
所以当 t 为 h时,结果为 1
当 t 小于( h+c ) / 2时,肯定为2 (一杯热水和一杯冷水)
当 t 属于 ( ( h+c ) / 2 , h )时,越加热水越靠近 ( h+c ) / 2,所以二分或者数学推导公式。
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,h,c,t;
double f(int x){
return ((x+1)*h+x*c)*1.0/(2*x+1);
}
signed main(){
scanf("%lld",&n);
while(n--){
scanf("%lld%lld%lld",&h,&c,&t);
if(t==h) printf("1\n");
else if(t*2<=(h+c)) printf("2\n");
else{
int x=(h-t)/(2*t-h-c);
if(fabs(t-f(x))<=fabs(t-f(x+1))) cout<<2*x+1<<endl;
else cout<<2*x+3<<endl;
}
}
return 0;
}