Files
python/TangDou/XiTi/1341.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

52 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
//交集求和
int GetSameCount(pair<int, int> a, pair<int, int> b) {
map<pair<int, int>, int> _map;
for (int i = a.first; i < a.second; i++) {
_map[make_pair(i, i + 1)]++;
}
for (int i = b.first; i < b.second; i++) {
_map[make_pair(i, i + 1)]++;
}
int count = 0;
//查找所有重复的数字段即2的
map<pair<int, int>, int>::iterator it;
for (it = _map.begin(); it != _map.end(); it++) {
auto c = *it;
if (c.second == 2) count++;
}
return count;
}
int main() {
int n;
cin >> n;
vector<pair<int, int>> H;
vector<pair<int, int>> W;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
H.push_back(make_pair(a, b));
}
for (int i = 0; i < n; i++) {
int c, d;
cin >> c >> d;
W.push_back(make_pair(c, d));
}
//计算交集
int sum = 0;
for (int i = 0; i < n; i++) {
pair<int, int> ab = H[i];
for (int j = 0; j < n; j++) {
pair<int, int> cd = W[j];
//求和
sum += GetSameCount(ab, cd);
}
}
cout << sum << endl;
return 0;
}