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 ...
随机推荐
- 20个Flutter实例视频教程-第06节: 酷炫的路由动画-2
博客地址: https://jspang.com/post/flutterDemo.html#toc-94f 视频地址: https://jspang.com/post/flutterDemo.htm ...
- LeetCode: 520 Detect Capital(easy)
题目: Given a word, you need to judge whether the usage of capitals in it is right or not. We define t ...
- Golang : flag 包简介
在 Golang 程序中有很多种方法来处理命令行参数.简单的情况下可以不使用任何库,直接处理 os.Args:其实 Golang 的标准库提供了 flag 包来处理命令行参数:还有第三方提供的处理命令 ...
- css3 display:box 属性
先看例子: .ub{ display: -webkit-box !important; display: box !important; position:relative;}.ub-f1{ posi ...
- API网络接口
1.天气 文章:http://segmentfault.com/a/1190000002607883 地址:http://api.lib360.net/open/weather.json?city=北 ...
- Lightoj1122 【数位DP】
题意: 给你m个数,让你在里面挑n个组合,保证位数相差不超过2,求能够组合多少种情况: 思路: dp[i][j]代表第i个结尾为j的方案数. #include<bits/stdc++.h> ...
- lightoj 1089 【离散化+线段树】
题意: 给你n个区间,然后给你m个i点问你这个点在几个所给定的区间里: 思路: 离散化+区间覆盖 #include <bits/stdc++.h> using namespace std; ...
- Unity的http通信--unity与python的django通信
http://blog.csdn.net/chenggong2dm/article/details/17372203 写在前面: WWW类,是unity里,简单的访问网页的类.本文介绍的就是这种方式, ...
- Cocos2d-x-html5之HelloWorld深入分析与调试
Cocos2d-x-html5之HelloWorld深入分析与调试 另:本章所用Cocos2d-x版本为: Cocos2d-html5-v2.1.1 http://cn.cocos2d-x.org/d ...
- jzoj5989. 【北大2019冬令营模拟2019.1.6】Forest (set)
题面 题解 为了一点小细节卡了一个下午--我都怕我瞎用set把电脑搞炸-- 观察一次\(1\)操作会造成什么影响,比如说把\(A[i]\)从\(x\)改成\(y\): \(D[x]\)会\(-1\), ...