Codeforces 1272A Three Friends(贪心)
思路:
贪心,移最左侧和最右侧的即可
代码:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
#define fi first
#define sc second
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pt(a) cerr<<a<<"---\n"
#define rp(i,n) for(int i=0;i<n;i++)
#define rpn(i,n) for(int i=1;i<=n;i++)
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int q;cin>>q;
while(q--){
int x[3];
rp(i,3)cin>>x[i];
sort(x,x+3);
if(x[2]-x[0]<=2) cout<<"0\n";
else cout<<(x[2]-x[0]-2)*2<<'\n';
}
return 0;
}