Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C. Lengthening Sticks
来源:互联网 发布:深圳冰川网络 市场策划 编辑:程序博客网 时间:2024/06/05 03:40
You are given three sticks with positive integer lengths of a, 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 integers a, 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.
1 1 1 2
4
1 2 3 1
2
10 2 1 7
0
In the first sample test you can either not increase any stick or increase any two sticks by1 centimeter.
In the second sample test you can increase either the first or the second stick by one centimeter. Note that the triangle made from the initial sticks is degenerate and thus, doesn't meet the conditions.
【题意】给出a,b,c,L,要求a+x,b+y,c+z构成三角形,x+y+z<=L,问有多少中分法(x,y,z可为0)。
【分析】不会这个题,题解可以看这个大牛的文章,http://blog.csdn.net/u013486414/article/details/47950919,我完全没想到这方法,总感觉是搜索什么的,实在太弱了。看了这题解才觉得这真的好题啊,考了一手脑洞和思维。解题方法参见上面blog。
【AC 代码】
#include <bits/stdc++.h>using namespace std;typedef long long LL;LL solve(LL a,LL b,LL c,LL l){ LL maxx = a+b+c+l; LL ans = 0; for(LL i=a; i<=a+l; i++){ if(b+c>i) continue; else{ LL x = min(i,maxx-i)-(b+c); ans += (x+2)*(x+1)/2; } } return ans;}int main(){ LL a,b,c,l; LL ans; scanf("%lld%lld%lld%lld",&a,&b,&c,&l); ans = (l+1)*(l+2)*(l+3)/6; ans -= solve(a,b,c,l); ans -= solve(b,a,c,l); ans -= solve(c,a,b,l); printf("%lld\n",ans); return 0;}
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C. Lengthening Sticks(数学)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C Lengthening Sticks(组合+容斥)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C. Lengthening Sticks
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1) A. Lengthening Sticks 分类
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)(A,B)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)A Arrays
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) D. Minimization
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Minimization dp
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C(组合数+容斥)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1) C. CNF 2 无向图找环
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C(组合数+容斥)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C(组合数+容斥)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1) B
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) B. Order Book
- A. Arrays------(Codeforces Round #317 [AimFund Thanks-Round] (Div. 2))
- B. Order Book------(Codeforces Round #317 [AimFund Thanks-Round] (Div. 2))
- 第二周项目2 程序的多文件组织
- 《TCP/IP详解 卷1:协议》 读书笔记 第6章 ICMP:Internet控制报文协议
- notifyDataSetChanged() 动态更新ListView 通过 Handler AsyncTask两种方式
- Servlet生命周期及创建方式
- 项目1-C/C++语言中函数参数传递的三种方式
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) C. Lengthening Sticks
- 第一行代码系列第二章——手动创建activity
- Android图片质量压缩以及缩略图生成
- Linux 基本指令
- jsp前后台传值那点小事
- TabLayout
- 使用VerticalBannerView实现垂直轮播广告(仿淘宝头条)
- SQL语句操作SQLite数据库Demo
- codeforces基础题——#361(div2)D