力扣双周赛 -- 117(容斥原理专场)

cpp 复制代码
class Solution {
public:
    long long c2(long long n)
    {
        return n > 1? n * (n - 1) / 2 : 0;
    }
    long long distributeCandies(int n, int limit) {
        
        
        return c2(n + 2) - 3 * c2(n - limit + 1) + 3 * c2(n - 2 * limit) - c2(n - 3 * limit - 1);
    }
};
相关推荐
NAGNIP7 小时前
一文搞懂机器学习中的特征降维!
算法·面试
NAGNIP8 小时前
一文搞懂机器学习中的特征构造!
算法·面试
Learn Beyond Limits8 小时前
解构语义:从词向量到神经分类|Decoding Semantics: Word Vectors and Neural Classification
人工智能·算法·机器学习·ai·分类·数据挖掘·nlp
你怎么知道我是队长8 小时前
C语言---typedef
c语言·c++·算法
Qhumaing10 小时前
C++学习:【PTA】数据结构 7-1 实验7-1(最小生成树-Prim算法)
c++·学习·算法
踩坑记录11 小时前
leetcode hot100 3.无重复字符的最长子串 medium 滑动窗口(双指针)
python·leetcode
Z1Jxxx11 小时前
01序列01序列
开发语言·c++·算法
汽车仪器仪表相关领域13 小时前
全自动化精准检测,赋能高效年检——NHD-6108全自动远、近光检测仪项目实战分享
大数据·人工智能·功能测试·算法·安全·自动化·压力测试
Doro再努力13 小时前
【数据结构08】队列实现及练习
数据结构·算法