题意:三角形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. Kafka基本操作

    cd kafka_2.11-0.11.0.1 bin/zookeeper-server-start.sh config/zookeeper.properties bin/kafka-server-st ...

  2. python2.7运行selenium webdriver api报错Unable to find a matching set of capabilities

    在火狐浏览器33版本,python2.7运行selenium webdriver api报错:SessionNotCreatedException: Message: Unable to find a ...

  3. 深入理解Java虚拟机 #01# 自己编译JDK

    x 首先用书上的脚本尝试,失败. 之后根据源文件的 README 编译,抛出: root@linux:/opt/openjdk# sh ./get_source.sh ERROR: Need init ...

  4. 20165310 学习基础和C语言基础调查

    学习基础和C语言基础调查 做中学体会 阅读做中学之后,了解老师关于五笔练习.减肥.乒乓和背单词的经历,不禁联想到自己学古筝的经历. 成功的经验 兴趣 我其实小时候学过一段时间古筝,但是那时候是因为父母 ...

  5. 20165310java_blog_week6

    2165310 <Java程序设计>第6周学习总结 教材学习内容总结 String 构造 String str=new String() String (char a[]) String ...

  6. 在Windows下搭建Android开发环境及遇到的问题

    转载1:http://www.cnblogs.com/xdp-gacl/p/4322165.html 转载2:http://www.cnblogs.com/zoupeiyang/p/4034517.h ...

  7. Java查找算法之二分查找

    二分查找是一种查询效率非常高的查找算法.又称折半查找. 一.算法思想 有序的序列,每次都是以序列的中间位置的数来与待查找的关键字进行比较,每次缩小一半的查找范围,直到匹配成功. 一个情景:将表中间位置 ...

  8. my normal Header

    #ifndef INCLUDES_MY #define INCLUDES_MY //默认登录名密码 #define DEFAULT_USERNAME "admin" #define ...

  9. Msys2的安装,并整合到cmder中

    下载:msys2-x86_64-20161025.exe 下载安装包,然后装上. 打开msys的shell之后首先升级一下pacman,然后就可以愉快地Syu了. $ pacman -Sy pacma ...

  10. 常见几种校验方法(CS和校验、CRC16、CRC32、BCC异或校验)

    总结一些通讯协议中常用到的几种校验方法: 1.CS和校验(如:标准188协议校验方式) /// <summary> /// CS和校验 /// </summary> /// & ...