2D Plane 2N Points

原创 2018年04月16日 13:54:21

2D Plane 2N Points

AtCoder - 3942

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

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

Sample Output 1

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

Sample Input 2

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

Sample Output 2

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

Sample Input 3

2
2 2
3 3
0 0
1 1

Sample Output 3

0
It is possible that no pair can be formed.

Sample Input 4

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

Sample Output 4

5

Sample Input 5

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

Sample Output 5

4

【解析】

这道题是一道二分图匹配的题目,很明显就是将文中的红点与蓝点进行匹配,模型如图:
这里写图片描述
如此,代码便是打版,易完成了。
附上二分匹配模板:

int PD(int x)
{
    for(int j=1;j<=n;j++)
    {
        if(line[x][j]&&!f[j])
        {
            f[j]=1;
            if(o_t[j]==0||PD(o_t[j]))
            {
                o_t[j]=x;
                return 1;
            }
        }
    }
    return 0;
}

AC代码:

#include<cstdio>
#include<cstring>
#define N 105
using namespace std;
int n,o_t[N];
int ans;
bool line[N][N],f[N];
struct node
{
    int x;int y;
}red[N];

struct node blue[N]; 

void read()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d %d",&red[i].x,&red[i].y);
    for(int i=1;i<=n;i++)
        scanf("%d %d",&blue[i].x,&blue[i].y);
}
int PD(int x)
{
    for(int j=1;j<=n;j++)
    {
        if(line[x][j]&&!f[j])
        {
            f[j]=1;
            if(o_t[j]==0||PD(o_t[j]))
            {
                o_t[j]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(red[i].x<blue[j].x&&red[i].y<blue[j].y)
            line[i][j]=1;
        }
    for(int i=1;i<=n;i++)
    {
        memset(f,0,sizeof f);
        if(PD(i)) ans++;
    }
    printf("%d",ans);
 } 
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37862149/article/details/79959672

2D动作手游-Spine骨骼动画

本课程是基于Spine骨骼动画实现的动作类手游,手游功能包括文本文件加密,技能系统,战斗系统,buff系统等,是一个功能齐全的游戏。
  • 2015年05月03日 22:00

【AtCoder Regular Contest 092】C.2D Plane 2N Points(二分图匹配,匈牙利算法)

备:有任何疑问或者交流都可以在下方留言。题意:给两个长度为n的序列的坐标,分别为(Ai,Bi),(Ci,Di),求最多有多少对坐标满足Ai&amp;lt;Ci并且Bi&amp;lt;Di。分析:将满足...
  • qq_36294146
  • qq_36294146
  • 2018-03-18 10:34:57
  • 33

【AtCoder Regular Contest 092】C.2D Plane 2N Points(匈牙利算法/tuple+set 贪心)

原题链接 题意:给两个长度为n的序列的坐标,分别为(Ai,Bi),(Ci,Di),求最多有多少对坐标满足Ai&amp;lt;Ci并且Bi&amp;lt;Di。 分析:将满足题中条件的坐标对的下标(...
  • feng_zhiyu
  • feng_zhiyu
  • 2018-03-17 22:20:49
  • 54

Atcoer 2D Plane 2N Points

2D Plane 2N PointsTime limit : 2sec / Memory limit : 256MBScore : 400 pointsProblem StatementOn a tw...
  • daguniang123
  • daguniang123
  • 2018-03-18 09:48:06
  • 33

Leetcode--->Given n points on a 2D plane, find the maximum number of points that lie on the same str

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line...
  • yyywww666
  • yyywww666
  • 2017-04-21 21:47:18
  • 650

2D Plane 2N Points-ATcoder092

Time limit : 2sec / Memory limit : 256MBScore : 400 pointsProblem StatementOn a two-dimensional plan...
  • hnustleoyue
  • hnustleoyue
  • 2018-03-18 13:56:22
  • 43

codeforces 576C Points on Plane

题意:给出n个点,要求排序后,相邻两点的欧拉距离之和小于等于2.5e9 做法:由于0≤ xi, yi ≤ 1e6,所以可以将x 然后每一份中的点都按照y单调排序。拿任意一份点做实验,如果从最小的y...
  • chaoweilanmao
  • chaoweilanmao
  • 2015-09-15 19:51:37
  • 697

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.

目标:求平面上在一条直线上最多的点的个数  首先想到了多点共线的规律就是两两之间的斜率相同,提到斜率又要考虑到斜率不存在的情况,即求斜率公式的分母为0.然而这边也存在两种情况,一个就是真的斜率不存在...
  • wang_cheng_hei
  • wang_cheng_hei
  • 2014-03-19 11:07:43
  • 1315

题目描述 Given n points on a 2D plane, find the maximum number of points that lie on the same straight

import java.util.*; public class Solution {     public int maxPoints(Point[] points) {         if...
  • wanganyu1996
  • wanganyu1996
  • 2017-04-14 16:27:18
  • 190

Leetcode: Max Points on a Line

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line....
  • doc_sgl
  • doc_sgl
  • 2013-12-03 22:57:09
  • 18703
收藏助手
不良信息举报
您举报文章:2D Plane 2N Points
举报原因:
原因补充:

(最多只允许输入30个字)