//571A - Lengthening Sticks
//数学题,容斥原理
//总的选择数C(l+3,3) la+lb+lc+unused=l;
//确定最长边,酱紫不构成三角形的充分必要条件就为 最长边>=其他两边和
//枚举最长边增量i,其他两边为b+lb,c+lc
//a+la>=b+lb+c+lc lb+lc<=l-la;
//x=min(a+la-b-c,l-la);
//则不构成三角形的数量为C(x+2,2);
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL solve(int a,int b,int c,int l){
LL ans=0;
for(int i=max(b+c-a,0);i<=l;i++){
LL x=min(a-b-c+i,l-i);
ans+=(LL)(x+1)*(LL)(x+2)/2;
}
return ans;
}
int main(){
int a,b,c,l;
scanf("%d%d%d%d",&a,&b,&c,&l);
long long tot=(LL)(l+1)*(LL)(l+2)*(LL)(l+3)/6;
tot-=solve(a,b,c,l);
tot-=solve(b,a,c,l);
tot-=solve(c,a,b,l);
printf("%lld\n",tot);
return 0;
}
CF571A - Lengthening Sticks(容斥)
最新推荐文章于 2019-03-16 19:52:43 发布