题意:三角形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. asp.net onclientclick事件刷新页面问题解决

      做网页经常要和JavaScript打交道,经常要用JavaScript做一些客户端的验证,但是如果我们的按钮用的是HTML控件的话,验证通过后无法调用后台代码,如果用服务器端控件,验证不通过有要刷 ...

  2. Python 迭代器切片

    函数itertools.islice() 正好适用于在迭代器和生成器上做切片操作 >>> def count(n): ... while True: ... yield n ... ...

  3. Python: 从字典中提取子集--字典推导

    问题: 构造一个字典,它是另外一个字典的子集 answer: 最简单的方式是使用字典推导 eg1: 1. >>>prices = {'ACME': 45.23, 'AAPL': 61 ...

  4. 数据仓库原理<3>:数据仓库与ODS

    1. 引言 本篇主要讲述操作数据存储(ODS)系统产生的背景.定义.特点,以及它与数据仓库的区别. 在前两篇,笔者介绍了什么是数据仓库?为什么需要数据仓库?数据仓库系统的体系结构是什么?因此可能在读者 ...

  5. RHEL6.4 字符模式下安装图形界面图文教程

    本文转自:http://www.cnblogs.com/wahsonleung/p/3230325.html 第1步:当然就是启动redhat,设置映像文件. 第2步:命令行输入yum groupin ...

  6. jquery easyUI中combobox的使用总结

    jquery easyUI中combobox的使用总结 一.如何让jquery-easyui的combobox像select那样不可编辑?为combobox添加editable属性 设置为false ...

  7. python的re正则表达式模块

    元字符  .   *   +   ?   ^   $   { }     [ ]     -     \ .  匹配除了/n之外的任意一个字符 * 匹配*前面的单个字符任意次,即[0,+∞] + 匹配 ...

  8. P2512 [HAOI2008]糖果传递&&P3156 [CQOI2011]分金币&&P4016 负载平衡问题

    P2512 [HAOI2008]糖果传递 第一步,当然是把数据减去平均数,然后我们可以得出一串正负不等的数列 我们用sum数组存该数列的前缀和.注意sum[ n ]=0 假设为链,那么可以得出答案为a ...

  9. Java实现Sybase数据库连接

    Java实现Sybase数据库连接 需要的jar包:jconn4.jar: Java代码: /** * @Title: getConnSybase * @Description: * @param * ...

  10. 強化 Python 在 Vim 裡的顏色

    我習慣用 putty 連 Unix server 開 screen,再用 vim 寫 Python.這篇記錄如何改善 Python 的顏色. 啟動 256 色 terminal 首先將可用的色彩數增加 ...