题目描述
链接:https://ac.nowcoder.com/acm/contest/33634/A
来源:牛客网
题意
思路
z=(c-a)*2,在满足是三角形、三边和为n、三边不相等条件下求最大边与最小边之差的最大值。
首先可有不等式推出a>1,找规律为b+1=c情况最大,注意求出的abc可能不满足三边不相等条件
code
#include<bits/stdc++.h>
// #define DEBUG(x) #x<<":"<<(x)<<' '
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
// const int mod=1e9+7;
// const int N;
void solv()
{
ll n,z,a,b,c;
cin>>n;
if(n<9)z=0;
else
{
if((n-2)&1)
{
a=2;
b=(n-2)/2;
c=b+1;
}
else
{
a=3;
b=(n-3)/2;
c=b+1;
}
if(a<b&&b<c)z=(c-a)*2;
else z=0;
}
cout<<z<<'\n';
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T=1;
cin>>T;
while(T--)
{
solv();
}
return 0;
}