题解:CF1814B Long Legs
CF1814B Long Legs
题意
给定起点
- 移动到
(x+m, y) 。 - 移动到
(x, y+m) 。 - 步长
m \rightarrow m+1 。
求从
思路
假设最终步长为
此时
目的是求
可以推出来
在
Code
#include<bits/stdc++.h>
#define int long long
#define double long double
#define bug cout<<"___songge888___"<<'\n';
using namespace std;
int t,a,b;
int ans;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>a>>b;
int m=sqrt(a+b);
ans=1e18;
for(int i=max(m-100,1ll);i<=m+100;i++){
ans=min(ans,(int)(ceil(a*1.0/i))+(int)(ceil(b*1.0/i))+i-1);
}
cout<<ans<<'\n';
}
return 0;
}
提交记录