题目的意思为要你求出满足三边范围条件且周长为n的三角形的数目。

其实做法是直接枚举最短边,然后就可以知道第二条边的取值范围,同时根据给定的范围缩小范围。

同时根据第二条边的范围推出第三条边的范围,再次缩小范围。此时范围里面的数就是此时最短边对应的可行数。

#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std; ll n,m,k,x[],y[],ans; ll Max(ll X,ll Y) { return X>Y?X:Y; }
ll Min(ll X,ll Y) { return X<Y?X:Y; } int main()
{
while (scanf("%I64d",&n)!=EOF)
{
for (ll i=; i<; i++) scanf("%I64d%I64d",&x[i],&y[i]);
ans=;
for (ll i=Max(x[],); i<=n/; i++)
{
ll tepx=Max(i,(n-*i)/+),tepy=(n-i)/;
tepx=Max(x[],tepx),tepy=Min(y[],tepy);
if (tepx>tepy) continue;
//cout<<i<<" : "<<tepx<<' '<<tepy<<endl;
tepx=n-i-tepx,tepy=n-i-tepy;
tepy=Max(x[],tepy),tepx=Min(y[],tepx);
if (tepy>tepx) continue;
ans+=tepx-tepy+;
}
printf("%I64d\n",ans);
}
return ;
}
04-21 04:53