本题链接: 买菜
本博客给出本题截图:
C++
#include <iostream> #include <algorithm> #define x first #define y second using namespace std; typedef pair<int, int> PII; const int N = 2010; int n; PII p[N], q[N]; int get(PII a, PII b) { if (a.y < b.x || b.y < a.x) return 0; return min(a.y, b.y) - max(a.x, b.x); } int main() { cin >> n; for (int i = 0; i < n; i ++ ) cin >> p[i].x >> p[i].y; for (int i = 0; i < n; i ++ ) cin >> q[i].x >> q[i].y; int res = 0; for (int i = 0; i < n; i ++ ) for (int j = 0; j < n; j ++ ) res += get(p[i], q[j]); cout << res << endl; return 0; }
总结
水题,不解释