A. Lengthening Sticks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 most l 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.

Input

The single line contains 4 integers a, b, c, l (1 ≤ a, b, c ≤ 3·105, 0 ≤ l ≤ 3·105).

Output

Print a single integer — the number of ways to increase the sizes of the sticks by the total of at most l centimeters, so that you
can make a non-degenerate triangle from it.

Sample test(s)
input
1 1 1 2
output
4
input
1 2 3 1
output
2
input
10 2 1 7
output
0
Note

In the first sample test you can either not increase any stick or increase any two sticks by 1 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.


题目链接:点击打开链接

题目大意:给出三条边的长度。能够给随意一条边添加随意的长度,可是添加的长度的总和不能超过l。问有多少种添加的方法,可使得三条边任然能组成一个三角形。

用总的方法数-不能组成三角形的方法数

首先求出全部的能添加的方法,假设三条边添加的长度和是l,那么一共同拥有C(l+2,2)种,计算出从0到l的全部的方法。

然后计算不能组成三角形的方法,假设最长边>=另外两边之和,那么就不是三角形,所以分别枚举a+i,b+i,c+i为最长边,然后计算有多少种不可能的办法。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
#define LL __int64
LL sum[300100] ;
LL solve(int a,int b,int c,int l) {
if( a < b+c ) return (LL)0 ;
LL ans = min(a-b-c,l) ;
return (ans+1)*(ans+2)/2 ;
}
int main() {
int a , b , c , l ;
LL i , ans ;
while( scanf("%d %d %d %d", &a, &b, &c, &l) != EOF ) {
sum[0] = 1 ;
for(i = 1 ; i <= l ; i++) {
sum[i] = (i+1)*(i+2)/2 + sum[i-1] ;
}
ans = sum[l] ;
for(i = 0 ; i <= l ; i++) {
ans -= solve(a+i,b,c,l-i) ;
ans -= solve(b+i,a,c,l-i) ;
ans -= solve(c+i,a,b,l-i) ;
}
printf("%I64d\n", ans) ;
}
return 0 ;
}

codeforces 571A--Lengthening Sticks(组合+容斥)的更多相关文章

  1. CF 317 A. Lengthening Sticks(容斥+组合数学)

    传送门:点我 A. Lengthening Sticks  time limit per test        1 second You are given three sticks with po ...

  2. codeforces 571a//Lengthening Sticks// Codeforces Round #317

    题意:三角形3条边,最多共添加ll长,问组成的合法三角形个数. 本来想用暴搜,觉得会超时就搜题解了.不过保证我解释得更清晰. 先计算ll长分配给3条边有几种分法?由于不分也是合法的,因此最后实际分出去 ...

  3. CodeForces571A. Lengthening Sticks(组合数学-容斥)

    题目大意: a,b,c三根木棍可以增加三个不同的数字,aa,bb,cc,且aa+bb+cc<=L,问能构成三角形的木棒有多少种方案 题目思路: 如果我们直接考虑把L分配给aa,bb,cc好像不好 ...

  4. bzoj4710: [Jsoi2011]分特产 组合+容斥

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 289  Solved: 198[Submit][Status] ...

  5. Codeforces Round #258 (Div. 2) 容斥+Lucas

    题目链接: http://codeforces.com/problemset/problem/451/E E. Devu and Flowers time limit per test4 second ...

  6. bzoj3622已经没有什么好害怕的了 dp+组合+容斥(?)

    3622: 已经没有什么好害怕的了 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1033  Solved: 480[Submit][Status][ ...

  7. Codeforces.449D.Jzzhu and Numbers(容斥 高维前缀和)

    题目链接 \(Description\) 给定\(n\)个正整数\(a_i\).求有多少个子序列\(a_{i_1},a_{i_2},...,a_{i_k}\),满足\(a_{i_1},a_{i_2}, ...

  8. BZOJ.4767.两双手(组合 容斥 DP)

    题目链接 \(Description\) 棋盘上\((0,0)\)处有一个棋子.棋子只有两种走法,分别对应向量\((A_x,A_y),(B_x,B_y)\).同时棋盘上有\(n\)个障碍点\((x_i ...

  9. Jzzhu and Numbers CodeForces - 449D (高维前缀和,容斥)

    大意: 给定集合a, 求a的按位与和等于0的非空子集数. 首先由容斥可以得到 $ans = \sum \limits_{0\le x <2^{20}} (-1)^{\alpha} f_x$, 其 ...

随机推荐

  1. 【转】坑爹的AsyncTask之根本停不下来

    原文网址:http://www.jianshu.com/p/0c6f4b6ed558 上篇<坑爹的AsyncTask之内存泄露>已经简单的探讨过线程使用不当会造成内存泄露的问题,在Acti ...

  2. Node.js:JXcore

    ylbtech-Node.js:JXcore 1.返回顶部 1. Node.js JXcore 打包 Node.js 是一个开放源代码.跨平台的.用于服务器端和网络应用的运行环境. JXcore 是一 ...

  3. mysql查询orderby

    --按某一字段分组取最大(小)值所在行的数据 /* 数据如下: name val memo a    2   a2(a的第二个值) a    1   a1--a的第一个值 a    3   a3:a的 ...

  4. mysql连接出现error node【1045】

    第一步:在my.ini下找到mysqlid.在后边添加skip-grant-tables 第二步:重新启动mysql服务 第三步:重新设置密码 第四步: 将skip-grant-tables删除掉,保 ...

  5. wp版笔记本应用源码

    今天在那个WP教程网看到了一个不错的项目,简单的记事本,主要是用到的独立存储文件的操作,TimePicker和DatePicker的是用,数据绑定,界面的参考的chanraycode的,主要是锻炼自己 ...

  6. sublime text 3 上安装xdebug

    安装完成之后启动xdebug,缺省设置下会显示warning等信息,很不方便. 可以参考 https://github.com/martomo/SublimeTextXdebug/blob/maste ...

  7. C# 获得指定路径扩展名 , 去除扩展名

    //指定扩展名的文件 private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; st ...

  8. 点击之后连接qq

    <a class=" "   style=""  href="http://wpa.qq.com/msgrd?v=3&uin=40482 ...

  9. UWP 利用DataGrid控件创建表格

    通过 Nuget 搜索 Microsoft.Toolkit.Uwp.UI.Controls.DataGrid 安装库,在XAML文件中添加引用库 xmlns:controls="using: ...

  10. 关于MySQL日期操作函数 date_formate 的使用

    基本语法:DATE_FORMAT(date,format)说明:date 参数是合法的日期.format 规定日期/时间的输出格式.可以用的格式主要有格式 描述%a 缩写星期名%b 缩写月名%c 月, ...