Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)
一个合法的三角形的充要条件是a<b+c,其中a为最长的一边,可以考虑找出所有不满足的情况然后用总方案减去不合法的情况。
对于一个给定的总长度tl(一定要分完,因为是枚举tl,不分配的长度已经考虑过了),分成三份,因为可以有两份为零,采用插空法的时候
增加两个假想长度为零的单位,所以方案数是C(tl+2,2),
假设a是增加长度以后最长的一边,r是tl减去给a增加长度之后剩下的长度,
那么不满足的情况的条件就可以写成a+tl-r>=b+c+r,很容易转化为r<=(a-b-c+tl)/2,显然r<=tl,如果r<0,
说明tl全部加到a上也不会超过b+c的和,方案数为0。对于剩下的r,分成三份lb,lc和没用上的,类似之前总长度的分配,方案数为C(r+2,2),
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll cal(int a,int b,int c,int tl)
{
int r = (a-b-c+tl)>>;
if(r<) return ;
if(r>tl) r = tl;
return (ll)(r+)*(r+)>>;
} int main()
{
int a,b,c,l; scanf("%d%d%d%d",&a,&b,&c,&l);
ll ans = ;
for(int i = ; i <= l; i++){
ans += (ll)(i+)*(i+)>>;
ans -= cal(a,b,c,i);
ans -= cal(b,a,c,i);
ans -= cal(c,a,b,i);
}
printf("%I64d",ans);
return ;
}
Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)的更多相关文章
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #317 (div 2)
Problem A Arrays 思路:水一水. #include<bits/stdc++.h> using namespace std; ; int n1,n2,k,m,a[N],b[N ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)
D. Minimization time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)
题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon 数学
C. Gerald's Hexagon Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/pr ...
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...
随机推荐
- OO易错点总结
在写子类的构造函数时,要在初始化列表中指定使用的父类的构造函数并完成其初始化,如下例: AudioBook(const string& bookname, const string& ...
- apk重签名的两种方法
因为robotium要求被测应用和测试代码要有一致的签名, 所以需要将apk包重签名. 方法一:通过re-sign.jar来产生debug key的apk(不适用于jdk 7以上) re-sign.j ...
- 【eclipse插件开发实战】Eclipse插件开发4——插件JDE、PDE开发方式及plugin.xml配置文件结构
Eclipse插件开发4--插件JDE.PDE开发方式及plugin.xml配置文件结构 开发方式分为:java开发环境JDE开发插件的方式和插件开发环境PDE开发插件方式. 插件通过添加到预定义的扩 ...
- HDU2222【AC自动机(基础·模板)】
Frist AC zi dong ji(Aho-Corasick Automation) of life #include <bits/stdc++.h> using namespace ...
- Android NDK开发指南(一) Application.mk文件
http://www.cnblogs.com/yaozhongxiao/archive/2012/03/06/2381586.html Application.mk目的是描述在你的应用程序中所需要的模 ...
- [Xcode 实际操作]一、博主领进门-(8)应用代理文件(AppDelegate.swift)详解
目录:[Swift]Xcode实际操作 本文将演示使用iOS模拟器,演示程序的生命周期. 在项目导航区,打开应用代理文件[AppDelegate.swift] 应用代理文件时系统运行本应用的委托,里面 ...
- [Xcode 实际操作]二、视图与手势-(3)UIView视图的基本操作
目录:[Swift]Xcode实际操作 本文将实现视图的添加与删除,以及切换视图在父视图中的层次. import UIKit class ViewController: UIViewControlle ...
- Peptidomics analysis of milk protein-derived peptides
released over time in the preterm infant stomach
(文献分享一组-陈凌云)
题目:Peptidomics analysis of milk protein-derived peptides released over time in the preterm infant st ...
- 反射记录点滴——Field
反射记录点滴 1. 反射获取类的属性 Class.getDeclareFileld(String name) 返回一个Filed对象,该对象反映此Class对象所表示的类或接口的指定已声明字段. Cl ...
- 安装Net::OpenSSH 库
perl 离线安装 Net::OpenSSH 库 Net::OpenSSH 库 下载地址https://metacpan.org/pod/Net::OpenSSH 直接获取安装包命令 wget htt ...