Problem Statement

On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (ai,bi), and the coordinates of the i-th blue point are (ci,di).

A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.

At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Constraints

  • All input values are integers.
  • 1≤N≤100
  • 0≤ai,bi,ci,di<2N
  • a1,a2,…,aN,c1,c2,…,cN are all different.
  • b1,b2,…,bN,d1,d2,…,dN are all different.

Input

Input is given from Standard Input in the following format:

N
a1 b1
a2 b2
:
aN bN
c1 d1
c2 d2
:
cN dN

Output

Print the maximum number of friendly pairs.


Sample Input 1

Copy
3
2 0
3 1
1 3
4 2
0 4
5 5

Sample Output 1

Copy
2

For example, you can pair (2,0) and (4,2), then (3,1) and (5,5).


Sample Input 2

Copy
3
0 0
1 1
5 2
2 3
3 4
4 5

Sample Output 2

Copy
2

For example, you can pair (0,0) and (2,3), then (1,1) and (3,4).


Sample Input 3

Copy
2
2 2
3 3
0 0
1 1

Sample Output 3

Copy
0

It is possible that no pair can be formed.


Sample Input 4

Copy
5
0 0
7 3
2 2
4 8
1 6
8 5
6 9
5 4
9 1
3 7

Sample Output 4

Copy
5

Sample Input 5

Copy
5
0 0
1 1
5 5
6 6
7 7
2 2
3 3
4 4
8 8
9 9

Sample Output 5

Copy
4
题意
给你n个二维坐标点A,再给n个二维坐标点B,如果B的x和y均大于A,这两个点可以匹配,求A的最大匹配
题解
一道二分图匹配的题,算是比较基础的题
当然这个题可以用贪心从小的开始,每次都选择B里与其最相近的元素
代码
 #include<bits/stdc++.h>
using namespace std; const int N=;
pair<int,int> p[N];
int vis[N],match[N];
int n;
int Find(int u)
{
for(int i=n+;i<=n+n;i++)
{
if(p[i].first>p[u].first&&p[i].second>p[u].second&&!vis[i])
{
vis[i]=;
if(!match[i]||Find(match[i]))
{
match[i]=u;
return ;
}
}
}
return ;
}
int main()
{
cin>>n;
for(int i=;i<=n+n;i++)
cin>>p[i].first>>p[i].second;
int ans=;
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(Find(i))
ans++;
}
cout<<ans;
return ;
}

AtCoder Regular Contest 092 C - 2D Plane 2N Points(二分图匹配)的更多相关文章

  1. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  2. 【AtCoder Regular Contest 092】C.2D Plane 2N Points【匈牙利算法】

    C.2D Plane 2N Points 题意:给定N个红点二维坐标N个蓝点二维坐标,如果红点横纵坐标都比蓝点小,那么它们能够构成一组.问最多能构成多少组. 题解:把满足要求的红蓝点连线,然后就是匈牙 ...

  3. AtCoder Regular Contest 092 C D E F

    C - 2D Plane 2N Points 题意 二维平面上有\(N\)个红点,\(N\)个蓝点,一个红点和一个蓝点能配成一对当且仅当\(x_r<x_b\)且\(y_r<y_b\). 问 ...

  4. AtCoder Regular Contest 092 2D Plane 2N Points AtCoder - 3942 (匈牙利算法)

    Problem Statement On a two-dimensional plane, there are N red points and N blue points. The coordina ...

  5. Atcoder Regular Contest 092 D - Two Faced Edges(图论+bitset 优化)

    Atcoder 题面传送门 & 洛谷题面传送门 orz ymx,ymx ddw %%% 首先既然题目要我们判断强连通分量个数是否改变,我们首先就将原图 SCC 缩个点呗,缩完点后我们很自然地将 ...

  6. Atcoder Regular Contest 092 A 的改编

    原题地址 题目大意 给定平面上的 $n$ 个点 $p_1, \dots, p_n$ .第 $i$ 点的坐标为 $(x_i, y_i)$ .$x_i$ 各不相同,$y_i$ 也各不相同.若两点 $p_i ...

  7. AtCoder Regular Contest 092 B Two Sequences

    题目大意 给定两个长为 $n$ 个整数序列 $a_1, \dots, a_n$ 和 $b_1, \dots, b_n$ .求所有 $a_i + b_j$($1\le i, j\le n$)的 XOR ...

  8. 思维定势--AtCoder Regular Contest 092 D - Two Sequences

    $n \leq 100000$的俩序列,数字范围$2^{28}$,问所有$a_i+b_j$的$n^2$个数字的异或和. 这种东西肯定是按位考虑嘛,从低位开始然后补上进位.比如说第一位俩串分别有$c$个 ...

  9. AtCoder Regular Contest 092 Two Sequences AtCoder - 3943 (二进制+二分)

    Problem Statement You are given two integer sequences, each of length N: a1,…,aN and b1,…,bN. There ...

随机推荐

  1. SonarQube与Jenkins结合提高代码质量

    首先,为什么需要SonarQube? 1.WriteClean Code 1)全局健康报告  2)关注新增的问题  3)强制QualityGate 4)Issue详情及建议- 详情参考:https:/ ...

  2. jsfl 将库中声音放置到时间轴上

    setBrokenFrames("cz1.mp3",2); /**/ /*<--------------将库中声音放置到时间轴上------------->*/ /** ...

  3. Mac 命令行,自定义命令

    例如自定义命令 gotoXFolder, 直接进入XFolder文件夹, XFolder地址为~/abc/def/Xfolder 步骤: 1. 在home文件夹下创建.profile文件 在.prof ...

  4. C#--构造函数的理解

    说白了构造函数就是用来初始化类的数据成员{因为C#语言具有类型安全的特质-->不能使用没有初始化的变量)} 在这里引用一下别人的总结,我觉得挺好的: 构造函数是一种特殊的成员函数,它主要用于为对 ...

  5. spark sql加载avro

    1.spark sql可以直接加载avro文件,之后再进行一系列的操作,示例: SparkConf sparkConf = new SparkConf().setAppName("Spark ...

  6. Python文件夹与文件的操作(转)

    最近在写的程序频繁地与文件操作打交道,这块比较弱,还好在百度上找到一篇不错的文章,这是原文传送门,我对原文稍做了些改动. 有关文件夹与文件的查找,删除等功能 在 os 模块中实现.使用时需先导入这个模 ...

  7. spring boot 程序打jar包及运行

  8. 使用pickle进行存储变量

    有时候我们需要把我们的变量内容存下来,这时我们就可以用pickle来操作. 存储操作如下所示: #!/usr/bin/python # -*- coding:utf-8 -*- import pick ...

  9. NYOJ20-吝啬的国度-图-dfs

    20-吝啬的国度 内存限制:64MB时间限制:1000ms特判: No 难度:3 题目描述: 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市, ...

  10. maven打包报错:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test

    mvn package的时候报如下错误: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test ...