Codeforces Round #643 (Div. 2) C. Count Triangles 题解(思维)

题目链接 题目思路 【Codeforces Round #643 (Div. 2) C. Count Triangles 题解(思维)】显然是找x+y>z即可,其实只要枚举x+y即可,自己好菜qwq
代码

#include #include using namespace std; typedef long long ll; int a,b,c,d; ll ans; int main(){ scanf("%d %d %d %d",&a,&b,&c,&d); for(int i=max(a+b,c); i<=b+c; i++){//枚举x+y int l=max(a,i-c),r=min(b,i-b); //枚举x的长度 ans+=1ll*(r-l+1)*(min(i-1,d)-c+1); } printf("%lld\n",ans); return 0; }

    推荐阅读