Pagini recente » Cod sursa (job #259155) | Cod sursa (job #2166988) | Cod sursa (job #699601) | Cod sursa (job #903708) | Cod sursa (job #329885)
Cod sursa(job #329885)
#include <cstdio>
#include <algorithm>
using namespace std;
#define file_in "hvrays.in"
#define file_out "hvrays.out"
#define Nmax 101000
#define mp make_pair
pair<int,int> H[Nmax],V[Nmax];
int T,h,v;
int nrr,ymax;
int main()
{
int i,j,x,y;
char s[20];
freopen(file_in,"r",stdin);
freopen(file_out,"w",stdout);
scanf("%d", &T);
while(T--)
{
scanf("%d %d", &h,&v);
for (i=1;i<=h;++i)
{
gets(s);
for(x=j=0;s[j]!=' ';++j)
x=x*10+s[j]-'0';
for(y=0,++j;s[j];++j)
y=y*10+s[j]-'0';
H[i]=mp(x,y);
}
for (i=1;i<=v;++i)
{
gets(s);
for(x=j=0;s[j]!=' ';++j)
x=x*10+s[j]-'0';
for(y=0,++j;s[j];++j)
y=y*10+s[j]-'0';
V[i]=mp(x,y);
}
sort(H+1,H+h+1);
sort(V+1,V+v+1);
ymax=-1;
nrr=0;
for (i=1;i<=h;++i)
{
if (H[i].first>ymax)
{
nrr++;
for (j=1;j<=v && H[i].second<=V[j].second;++j)
ymax=max(ymax,V[j].first);
}
}
printf("%d\n", nrr);
}
fclose(stdin);
fclose(stdout);
return 0;
}