Let‘s Chat
///@author Sycamore, ZJNU ///@date 4/22/2017 #include <iostream> #include <sstream> #include <iomanip> #include <cmath> #include <string> #include <algorithm> #include <numeric> #include <functional> #include <vector> #include <set> #include <list> #include <stack> #include <queue> #include <map> #include <algorithm> #include <cctype> #include<fstream> //#define cin fin //#define cout fout //ifstream fin("in.txt"); //ofstream fout("out.txt"); using namespace std; typedef vector<int> VI; typedef pair<int, int> PII; int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T--) { int n, m, AtoB, BtoA; cin >> n >> m >> AtoB >> BtoA; vector<int>AB(2 * AtoB); for (auto &e : AB)cin >> e; vector<int>BA(2 * BtoA); for (auto &e : BA)cin >> e; long long fs = 0; for (int i = 0; i<2 * AtoB; i += 2) for (int j = 0; j <2 * BtoA; j += 2) { if (AB[i] > BA[j + 1] || AB[i + 1] < BA[j])continue; int cons = min(AB[i + 1], BA[j + 1]) - max(AB[i], BA[j]) + 1; if (cons >= m)fs += cons - m + 1; } cout << fs << endl; } return 0; }
原文:http://www.cnblogs.com/zjnu/p/7296325.html