Pagini recente » Cod sursa (job #2493480) | Cod sursa (job #2021211) | Cod sursa (job #605216) | Cod sursa (job #1775540) | Cod sursa (job #1305247)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f ("hvrays.in");
ofstream g ("hvrays.out");
const int NMAX = 100000 + 1;
struct Raza {
int x, y;
};
int t, h, v;
Raza H[NMAX], V[NMAX];
void citeste() {
f >> h >> v;
for (int i = 1; i < h; i++) f >> H[i].x >> H[i].y;
for (int i = 1; i < v; i++) f >> H[i].x >> H[i].y;
}
inline bool comp(Raza a, Raza b) {
return a.x > b.x;
}
void rezolva() {
int maxim = 0, sol = 0;
for (int i = 1, j = 1; i <= h; i++)
if (H[i].y > maxim) {
sol++;
while(j <= v && V[j].x >= H[i].x) {
maxim = max(maxim, V[j].y);
j++;
}
}
g << sol << '\n';
}
int main() {
f >> t;
while (t--) {
citeste();
sort(H + 1, H + h + 1, comp);
sort(V + 1, V + v + 1, comp);
rezolva();
}
return 0;
}