CodeForces
来源:互联网 发布:nba2k17麦迪动作数据 编辑:程序博客网 时间:2024/05/16 15:53
题目描述:
点击打开链接
题意给你a,b,c,l你可以给a,b,c三条边加任意长度但是加的总长不能超过l,求多种可以组成三角形的方案。仍然容斥倒着计数,先算出总方案用隔板法累加(i+1)(i+2)/2;然后枚举最长边分别为a,b,c最长边的增长长度为0到l的情况,算出不能形成三角形的方案,减去即可。
AC代码:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<stack>#include<vector>#include<queue>#include<algorithm>using namespace std;const int MAXM=25;const long long MOD=1000000007;long long handle(int a,int b,int c,int l){ if (a<b+c) return 0LL; long long ans=min(a-b-c,l); return (ans+1)*(ans+2)/2;}int a,b,c,l;long long sum[301000];int main(){ while(scanf("%d%d%d%d",&a,&b,&c,&l)!=EOF) { sum[0]=1; for (long long i=1;i<=l;i++) sum[i]=sum[i-1]+(i+1)*(i+2)/2; long long ans=sum[l]; for (int i=0;i<=l;i++) { ans=ans-handle(a+i,b,c,l-i); ans=ans-handle(b+i,a,c,l-i); ans=ans-handle(c+i,a,b,l-i); } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 【webpack】style-loader错误
- hdu 6170 Two strings dp
- java中的break和continue语句
- POJ 3253 Fence Repair(STL之优先队列)
- ImageLorder的基本使用
- CodeForces
- F
- 重装系统后安装驱动的一点小技巧
- NOI 2015 程序自动分析
- LCD(二):LCD常用接口原理篇
- leetcode 480. Sliding Window Median
- flask网站加入验证码功能的几个问题
- 天天学Linux命令2--ls命令
- 通过广播进行网络状态监听