每日两题day68

今天你AC了吗?

每日两题day68


一、基础题

题目:P5732 【深基5.习7】杨辉三角 - 洛谷

思路:

找好递推公式就好了

代码:

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        a[i][0] = 1;
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= i; j++) {
            a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}

二、提高题

题目:P1102 A-B 数对 - 洛谷

思路:

map秒了,2^30记得开longlong

代码:

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    map<long long, long long> mp;
    set<long long> s;
    long long n, c;
    cin >> n >> c;
    while (n--) {
        int x;
        cin >> x;
        mp[x]++;
        s.insert(x);
    }
    long long cnt = 0;
    for (auto i: s) {
        cnt += mp[i] * mp[i + c];
    }
    cout << cnt << "\n";
    return 0;
}
相关推荐
IronMurphy34 分钟前
【算法四十三】279. 完全平方数
算法
墨染天姬41 分钟前
【AI】Hermes的GEPA算法
人工智能·算法
papership1 小时前
【入门级-数据结构-3、特殊树:完全二叉树的数组表示法】
数据结构·算法·链表
smj2302_796826521 小时前
解决leetcode第3911题.移除子数组元素后第k小偶数
数据结构·python·算法·leetcode
Beginner x_u2 小时前
链表专题:JS 实现原理与高频算法题总结
javascript·算法·链表
_深海凉_5 小时前
LeetCode热题100-寻找两个正序数组的中位数
算法·leetcode·职场和发展
旖-旎6 小时前
深搜练习(电话号码字母组合)(3)
c++·算法·力扣·深度优先遍历
谭欣辰6 小时前
C++快速幂完整实战讲解
算法·决策树·机器学习
Mr_pyx6 小时前
【LeetHOT100】随机链表的复制——Java多解法详解
算法·深度优先
AIFarmer6 小时前
【无标题】
开发语言·c++·算法