今天你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;
}