Lengthening Sticks CodeForces
来源:互联网 发布:网络建设服务商 编辑:程序博客网 时间:2024/06/05 02:53
Lengthening Sticks
You are given three sticks with positive integer lengths ofa, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at mostl centimeters. In particular, it is allowed not to increase the length of any stick.
Determine the number of ways to increase the lengths of some sticks so that you can form from them a non-degenerate (that is, having a positive area) triangle. Two ways are considered different, if the length of some stick is increased by different number of centimeters in them.
The single line contains 4 integersa, b, c, l (1 ≤ a, b, c ≤ 3·105,0 ≤ l ≤ 3·105).
Print a single integer — the number of ways to increase the sizes of the sticks by the total of at mostl centimeters, so that you can make a non-degenerate triangle from it.
Input
1 1 1 2
4
1 2 3 1
#include<bits/stdc++.h>using namespace std;typedef long long ll;ll work(ll a,ll b,ll c,ll l){ ll s=0; ll mn=0; ll mx=a+b+c+l; for(ll i=a;i<=a+l;i++) { if(b+c<=i) { mn=min(mx-i,i)-b-c; s+=1ll*(mn+1)*(mn+2)/2; } } return s;}int main(){ ll a,b,c,l; while(scanf("%lld%lld%lld%lld",&a,&b,&c,&l)!=EOF) { ll ans=0; for(ll i=0;i<=l;i++) ans+=(i+2)*(i+1)/2; ans-=work(a,b,c,l); ans-=work(b,a,c,l); ans-=work(c,a,b,l); printf("%I64d\n",ans); } return 0;}
- Lengthening Sticks CodeForces
- codeforces 571 A Lengthening Sticks
- Lengthening Sticks - Codeforces 571 A
- codeforces 571 A. Lengthening Sticks
- codeforces 317 A - Lengthening Sticks
- 【codeforces 572C】Lengthening Sticks
- Codeforces Round #317 A.Lengthening Sticks
- [组合] Codeforces #571A. Lengthening Sticks
- CodeForces #317 (div2) C.Lengthening Sticks (容斥)
- codeforces 571A--Lengthening Sticks(组合+容斥)
- C. Lengthening Sticks(Codeforces Round #317 容斥定理)
- codeforces #317 C. Lengthening Sticks (很好的想法题)
- Codeforces Round #317 A. Lengthening Sticks(组合+容斥)
- 容斥 + 组合数学 ---Codeforces Round #317 A. Lengthening Sticks
- 571A Lengthening Sticks
- codeforces571A. Lengthening Sticks
- CF571A - Lengthening Sticks(容斥)
- cf Div#317 Lengthening Sticks
- IDEA jrebel热部署
- Python相关资源
- 7个因素决定大数据的复杂性
- ios 怎么让子视图不响应父视图的手势识别器呢?
- 有一个超毒舌的对象是什么体验?
- Lengthening Sticks CodeForces
- Mybatis中javaType和jdbcType关系对照表
- java IO笔记(Reader/Writer)
- 微信小程序----组件之radio
- JavaSE(八)之集合概述
- java中两种跳转方式:从定向和请求转发
- HDU 6053 TrickGCD(莫比乌斯反演)
- mybatis插件 mybatis-generator的使用
- 文件上传(类型限制)及删除实例