Pagini recente » Cod sursa (job #1223048) | Cod sursa (job #2012496) | Cod sursa (job #40543) | Cod sursa (job #1473312) | Cod sursa (job #2014201)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#define NMAX 100005
using namespace std;
ifstream si("hvrays.in");
ofstream so("hvrays.out");
string buf;
string::iterator bit;
void citint(int &x)
{
for(;*bit>'9'||*bit<'0';++bit);
for(x=0;*bit<='9'&&*bit>='0';++bit)
{
x=x*10+*bit-'0';
}
}
struct str
{
int x,y;
};
str h[NMAX+1],v[NMAX+1];
bool cmp(str x,str y)
{
if(x.x==y.x)
{
return x.y>y.y;
}
return x.x>y.x;
}
int main()
{
getline(si,buf,(char)0);
bit=buf.begin();
int t;
citint(t);
for(int q=1;q<=t;++q)
{
int n,m;
citint(n);
citint(m);
for(int i=1;i<=n;++i)
{
citint(h[i].x);
citint(h[i].y);
}
sort(h+1,h+n+1,cmp);
for(int i=1;i<=m;++i)
{
citint(v[i].x);
citint(v[i].y);
}
sort(v+1,v+m+1,cmp);
int sol=0;
for(int i=1,j=1,aux=-1;i<=n;++i)
{
if(aux<h[i].y)
{
for(++sol;j<=m&&h[i].x<=v[j].x;++j)
{
if(aux<v[j].y)
{
aux=v[j].y;
}
}
}
}
so<<sol<<'\n';
}
return 0;
}