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 ...
随机推荐
- B. Vanya and Food Processor【转】
B. Vanya and Food Processor time limit per test 1 second memory limit per test 256 megabytes input s ...
- 1.8-1.10 大数据仓库的数据收集架构及监控日志目录日志数据,实时抽取之hdfs系统上
一.数据仓库架构 二.flume收集数据存储到hdfs 文档:http://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html#hd ...
- UVa 1001 Say Cheese (Dijkstra)
题意:给定一个三维空间的一些球和起始位置和结束位置,问你最短要花的时间是多少. 析:建图,所有的位置都建立图,边权就是距离,最小求一次最短路即可. 代码如下: #pragma comment(link ...
- 451. Sort Characters By Frequency (sort map)
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- 5-5 城市间紧急救援 (25分)【最短路spfa】
5-5 城市间紧急救援 (25分) 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速 ...
- hyperledger fabric 1.0.5 分布式部署 (三)
本篇博客主要是向读者介绍 fabric 在部署时的一些细节,还有作者自己学习过程中的心得. 初始化相关密钥的程序,实际上是一个shell脚本,并且结构特别简单 generateArtifacts.sh ...
- SpringBoot | 查看默认版本配置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- [题解](区间质数筛)POJ_2689 Prime Distance
区间筛素数:先筛出1~sqrt(R)的素数,然后对于每个询问只要用这些素数筛掉区间内的合数即可. 几个细节:1.特判和1有关的一些情况 2.每次减去L偏移量,数组只开区间大小 3.POJ无法使用万能头 ...
- [题解]luogu_AT1224_JOIOJI
https://www.cnblogs.com/fengzhiyuan/p/7588443.html 不会map,有点菜 1.要想知道三个字母出现次数相等, 为J [ i ]-J [ j ]== O[ ...
- ERROR: Could not connect to lockdownd, error code -19 -20
执行命令行 brew install libimobiledevice --HEAD