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
    #include
    #include
    #include
    #include
    using namespace std;
    int cnt[10008];
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            vector,int> > a;
            int x,y;
            for(int i=0; i> x>> y;
                a.push_back(make_pair(make_pair(x,y),0));
            }
            for(int i=0; i> 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=0;j--){
                        if(cnt[j]>0){
                            cnt[j]--;
                            ans++;
                            break;
                        }
                    }
                }
            }
            cout<

你可能感兴趣的:(ATcoder)