题意:三角形3条边,最多共添加ll长,问组成的合法三角形个数。

本来想用暴搜,觉得会超时就搜题解了。不过保证我解释得更清晰。

先计算ll长分配给3条边有几种分法?由于不分也是合法的,因此最后实际分出去的量从0-ll都有可能。for循环枚举实际分的量(记为i)。对于每个x,分为m,p,q三份(每份可为0),相当于x+3分为,m+1,p+1,q+1(每份不可为0),相当于x+3长度上(中间只有x+2个间隔,选2个)切不同的两刀。因此就是循环(x+2)*(x+2-1)/(2*(2-1));

然后计算分法中不合法的数量。假如a是分完后最长的,那么a至少要分i=(b+c-a)长,b+c-a到ll之间枚举a增加的长度i,还剩ll-i,b和c的总和不超过a,因此bc增加的长度小于a+i-(b+c),因此bc能增加的总长度在0-min(ll-i,a+i-(b+c))之间,用上面分三份的方法计算分两份的组合。

乱码:

#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon; lon sub(lon a,lon b,lon c,lon ll)
{
lon res=;
for(lon i=max((lon),b+c-a);i<=ll;++i)
{
lon less=min(ll-i,a+i-(b+c));
res+=less++less*(less+)/;
}
//cout<<"res: "<<res<<endl;
return res;
} int main()
{
std::ios::sync_with_stdio();
lon a,b,c,ll;
cin>>a>>b>>c>>ll;
lon res=;
for(lon i=;i<=ll;++i)
{
res+=(i+-)*(i+-)/;
}
//cout<<res<<endl;
res-=sub(a,b,c,ll);
res-=sub(b,c,a,ll);
res-=sub(c,a,b,ll);
cout<<res<<endl;
return ;
}

codeforces 571a//Lengthening Sticks// Codeforces Round #317的更多相关文章

  1. 571A Lengthening Sticks

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  2. 容斥 + 组合数学 ---Codeforces Round #317 A. Lengthening Sticks

    Lengthening Sticks Problem's Link: http://codeforces.com/contest/571/problem/A Mean: 给出a,b,c,l,要求a+x ...

  3. Codeforces #317 C.Lengthening Sticks(数学)

    C. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #317 (div 2)

    Problem A Arrays 思路:水一水. #include<bits/stdc++.h> using namespace std; ; int n1,n2,k,m,a[N],b[N ...

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

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

  6. Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)

    一个合法的三角形的充要条件是a<b+c,其中a为最长的一边,可以考虑找出所有不满足的情况然后用总方案减去不合法的情况. 对于一个给定的总长度tl(一定要分完,因为是枚举tl,不分配的长度已经考虑 ...

  7. Codeforces Round #425 (Div. 2) Problem A Sasha and Sticks (Codeforces 832A)

    It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day h ...

  8. Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Minimization dp

    原题链接:http://codeforces.com/contest/572/problem/D 题意 给你个数组A和n,k,问你排列A后,下面的最小值是多少. 题解 先排个序,要填充像1,1+k,1 ...

  9. Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟

    原题链接:http://codeforces.com/contest/572/problem/B 题意 很迷,自行看题. 题解 看懂题就会做了 代码 #include<iostream> ...

随机推荐

  1. 基于Axis1.4的webservice接口开发(环境搭建)

    基于Axis1.4的webservice接口开发(环境搭建) 一.环境搭建: 1.搜索关键字“Axis1.4”下载Axis1.4相关的jar包. 下载地址:http://download.csdn.n ...

  2. 关于 enhanced decompiler 3.0 .0不起作用的解决办法

  3. python json-json.loads()函数中的字符串需要是严格的json串格式,不能包含单引号

    先看下json的dumps()和loads()函数的定义 json.dumps():将一个Python对象编码成JSON字符串.把字典对象转换成json串 json.loads():将JSON格式字符 ...

  4. python读取剪贴板报错 pywintypes.error: (1418, 'GetClipboardData', '\xcf\xdf\xb3\xcc\xc3\xbb\xd3\xd0\xb4\xf2\xbf\xaa\xb5\x

    在封装读取剪贴板的时候,执行测试代码时遇到个错误: pywintypes.error: (1418, 'GetClipboardData', '\xcf\xdf\xb3\xcc\xc3\xbb\xd3 ...

  5. Linux基础命令---eject

    eject eject指令允许在软件控制下弹出可移动媒体(通常是光盘.软盘.磁带或Jaz或ZIP磁盘).该命令还可以控制一些由某些设备支持的自动弹出功能的多光盘转换器,并关闭一些光盘驱动器的盘. 对应 ...

  6. keepalived+lvs高可用集群

    LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国 ...

  7. MySQL备份与恢复-innobackupex

    :上一片myloder搞崩溃,为什么百度的博文都是抄袭一模一样的,哎烦! 这一片文章我们来介绍物理备份工具xtracebackup! 首先是安装可以percona官网下载安装,下载rpm包直接yum安 ...

  8. OpenCV中HSV颜色模型及颜色分量范围

    HSV颜色模型 HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色空间, 也称六角锥体模型(Hexcone Model)..这 ...

  9. tcp网络通信的三次握手与三次挥手

    背景描述 通过上一篇中网络模型中的IP层的介绍,我们知道网络层,可以实现两个主机之间的通信.但是这并不具体,因为,真正进行通信的实体是在主机中的进程,是一个主机中的一个进程与另外一个主机中的一个进程在 ...

  10. luogu3935 Calculating

    标题也许叫整除分块吧 求\(1\)到\(n\)因数的个数\(\sum_{i=1}^n(\sum_{d|n}1)\) 范围\(1e14\)时限3s \(n\sqrt{n}\)的暴力铁定gg 分开考虑 \ ...