2D Plane 2N Points-ATcoder092

Time limit : 2sec / Memory limit : 256MB

Score : 400 points

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.
  • 1N100
  • 0ai,bi,ci,di<2N
  • a1,a2,…,aN,c1,c2,…,cN are all different.
  • b1,b2,…,bN,d1,d2,…,dN are all different.
    #include<algorithm>
    #include<cstdio>
    #include<iostream>
    #include<vector>
    #include<cstring>
    using namespace std;
    int cnt[10008];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            vector<pair<pair<int,int>,int> > a;
            int x,y;
            for(int i=0; i<n; i++)
            {
                cin >> x>> y;
                a.push_back(make_pair(make_pair(x,y),0));
            }
            for(int i=0; i<n; i++)
            {
                cin >> x>> y;
               a.push_back(make_pair(make_pair(x,y),1));
            }
            sort(a.begin(),a.end());
            int ans=0;
            memset(cnt,0,sizeof(cnt));
            for(int i=0;i<a.size();i++){
                if(a[i].second==0)
                {
                    cnt[a[i].first.second]++;
                }
                else{
                    for(int j=a[i].first.second-1;j>=0;j--){
                        if(cnt[j]>0){
                            cnt[j]--;
                            ans++;
                            break;
                        }
                    }
                }
            }
            cout<<ans<<endl;
        }
    }
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值