AC(博主的纯数学做法)
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
const int N = 2e5+10;
const int M = 1e4;
ll h,c,t;
struct Type{
ll t1, t2;
ll res;
bool operator<(const Type x)const{
if(abs(t1*x.t2 - t*t2*x.t2) != abs(x.t1*t2-t*x.t2*t2))
return abs(t1*x.t2 - t*t2*x.t2) < abs(x.t1*t2-t*x.t2*t2);
else return res<x.res;
}
};
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tt;
cin>>tt;
while(tt--){
cin>>h>>c>>t;
if(h<=t)cout<<1<<endl;
else if(h+c>=t*2)cout<<2<<endl;
else {
ll ss = t-c;
ll s = 2*t-c-h;
ll res = ss/s;
ll ans = res*2-1;
vector<Type> v;
ll t1 ;
ll t2;
if(res){
t1 = (res-1)*(h+c)-c;
t2 = 2*(res-1)-1;
v.pb({
t1,t2,res-1});
}
t1 = (res)*(h+c)-c;
t2 = 2*(res)-1;
v.pb({
t1,t2,res});
t1 = (res+1)*(h+c)-c;
t2 = 2*(res+1)-1;
v.pb({
t1,t2,res+1});
sort(v.begin(),v.end());
cout<<(v[0].res*2-1)<<endl;
}
}
return 0;
}
AC(某位红名大佬的二分)
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {
c b, e; };
sim > rge<c> range(c i, c j) {
return rge<c>{
i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() {
cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) {
ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
ll gor, zim, chce;
pll ula(ll v)
{
ll mi=2*v+1;
ll li=v*(gor+zim)+gor;
return {
li, mi};
}
void test()
{
scanf("%lld%lld%lld", &gor, &zim, &chce);
gor<<=1;
zim<<=1;
chce<<=1;
if (chce<=(gor+zim)/2)
{
printf("2\n");
return;
}
ll bsa=0;
ll bsb=1e6;
while(bsa<bsb)
{
ll bss=(bsa+bsb+2)>>1;
pll wez=ula(bss);
if (wez.first>=chce*wez.second)
bsa=bss;
else
bsb=bss-1;
}
ll lew=bsa;
ll pra=bsa+1;
pll wl=ula(lew);
pll wp=ula(pra);
pll sr={
wl.first*wp.second+wp.first*wl.second, wl.second*wp.second*2};
if (sr.first<=chce*sr.second)
printf("%lld\n", 2*lew+1);
else
printf("%lld\n", 2*pra+1);
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
test();
return 0;
}