codeforces 571a//Lengthening Sticks// Codeforces Round #317
题意:三角形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的更多相关文章
- 571A Lengthening Sticks
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 容斥 + 组合数学 ---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 ...
- Codeforces #317 C.Lengthening Sticks(数学)
C. Lengthening Sticks time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #317 (div 2)
Problem A Arrays 思路:水一水. #include<bits/stdc++.h> using namespace std; ; int n1,n2,k,m,a[N],b[N ...
- CF 317 A. Lengthening Sticks(容斥+组合数学)
传送门:点我 A. Lengthening Sticks time limit per test 1 second You are given three sticks with po ...
- Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)
一个合法的三角形的充要条件是a<b+c,其中a为最长的一边,可以考虑找出所有不满足的情况然后用总方案减去不合法的情况. 对于一个给定的总长度tl(一定要分完,因为是枚举tl,不分配的长度已经考虑 ...
- 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 ...
- 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 ...
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2) Order Book 模拟
原题链接:http://codeforces.com/contest/572/problem/B 题意 很迷,自行看题. 题解 看懂题就会做了 代码 #include<iostream> ...
随机推荐
- 谷歌浏览器 URL无法访问
使用谷歌浏览器老是会崩溃,或者访问的时候发现“URL无法访问”等失败的问题,连淘宝都没法访问,这个让人很恼火, 最后在扩展应用那里搜到个URL的redirect,问题解决了,~~发现没有再出现类似问题 ...
- OS X 下动态库的引用
foo.c #include <stdio.h> void foo(void) { printf("foo.\n"); } main.c #include <st ...
- Hive表中Partition的创建
作用: 在Hive Select查询中一般会扫描整个表内容,会消耗很多时间做没必要的工作.有时候只需要扫描表中关心的一部分数据,在对应的partition里面去查找就可以,减少查询时间. 1. 创建表 ...
- linux常用命令:tar 命令
通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...
- win10如何设置自动睡眠时间(修改电源计划不好用的情况下)
https://answers.microsoft.com/en-us/windows/forum/windows_10-power/windows-10-sleeping-when-set-not- ...
- jackson 常用注解,比如忽略某些属性,驼峰和下划线互转
一般情况下使用JSON只使用了java对象与字符串的转换,但是,开发APP时候,我们经常使用实体类来做转换:这样,就需要用到注解: Jackson默认是针对get方法来生成JSON字符串的,可以使用注 ...
- 在win和android上同时进行OpenCV程序设计
基于qt进行Android图像处理项目设计的时候,初期可以首先在windows上进行调试,等到比较成熟后将代码转换到adnroid上. 这里仅以widget为例,如果使用qtquick是一样的.具体以 ...
- 洛谷月赛 Hello World(升级版) - 动态规划
题目背景 T1答案要mod1000000007(10^9+7),请重新提交,非常抱歉! 一天,智障的pipapi正在看某辣鸡讲义学程序设计. 题目描述 在讲义的某一面,他看见了一篇文章.这篇文章由英文 ...
- 自动化测试框架Cucumber和RobotFramework的实战对比
转自: http://www.infoq.com/cn/articles/cucumber-robotframework-comparison 一.摘要 自动化测试可以快速自动完成大量测试用例,节 ...
- Java初始化块的作用
1.使代码更简洁 eg: public class Test { private void init() { System.out.println("初始化状态"); } publ ...