zoukankan      html  css  js  c++  java
  • hdu 4268 Alice and Bob

    Alice and Bob

    Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 5   Accepted Submission(s) : 1

    Font: Times New Roman | Verdana | Georgia

    Font Size: ← →

    Problem Description

    Alice and Bob's game never ends. Today, they introduce a new game. In this game, both of them have N different rectangular cards respectively. Alice wants to use his cards to cover Bob's. The card A can cover the card B if the height of A is not smaller than B and the width of A is not smaller than B. As the best programmer, you are asked to compute the maximal number of Bob's cards that Alice can cover.
    Please pay attention that each card can be used only once and the cards cannot be rotated.

    Input

    The first line of the input is a number T (T <= 40) which means the number of test cases.
    For each case, the first line is a number N which means the number of cards that Alice and Bob have respectively. Each of the following N (N <= 100,000) lines contains two integers h (h <= 1,000,000,000) and w (w <= 1,000,000,000) which means the height and width of Alice's card, then the following N lines means that of Bob's.

    Output

    For each test case, output an answer using one line which contains just one number.

    Sample Input

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

    Sample Output

    1
    2
    题意:两组卡片,第一组的某一张卡片的长并且宽大于等于第二组某一张卡片的长和宽(x,y), 加1;
    先sort排序下,利用multiset去存第二组的y,multiset容器可以存相同的元素
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<set>
     7 #include<map>
     8 #include<queue>
     9 #include<vector>
    10 //#define INF 0x3f3f3f3f
    11 #define N 100005
    12 typedef long long ll;
    13 using namespace std;
    14 struct node{
    15     int x;
    16     int y;
    17 }a[N],b[N];
    18 bool cmp(node aa,node bb){
    19     if(aa.x==bb.x){
    20         return aa.y<bb.y;
    21     }
    22     else
    23         return aa.x<bb.x;
    24 }
    25 int main()
    26 {
    27     int t,n;
    28     scanf("%d",&t);
    29     int i,j;
    30     while(t--)
    31     {
    32         scanf("%d",&n);
    33         for(i=0;i<n;i++)
    34             scanf("%d%d",&a[i].x,&a[i].y);
    35         sort(a,a+n,cmp);
    36         for(i=0;i<n;i++)
    37             scanf("%d%d",&b[i].x,&b[i].y);
    38         sort(b,b+n,cmp);
    39         multiset<ll>st;
    40         multiset<ll>::iterator it;
    41         int ans=0;
    42         st.clear();
    43         j=0;
    44         for(i=0;i<n;i++){
    45             while(a[i].x>=b[j].x&&j<n){
    46                     st.insert(b[j].y);
    47                     j++;
    48             }
    49             if(st.empty())
    50                 continue;
    51             it=st.upper_bound(a[i].y);
    52             if(it!=st.begin())
    53             {
    54                 it--;
    55                 ans++;
    56                 st.erase(it);
    57             }
    58         }
    59         printf("%d
    ",ans);
    60     }
    61 }
  • 相关阅读:
    Redis学习-开始
    MongoDb学习1
    Git删除tag
    简单实现Windows服务 TopShelf
    autofac 注入普通服务和WCF服务
    MVC过滤器之 OnActionExcuted
    jquery的$.extend()、$.fn和$.fn.extend()
    quartz_jobs.xml标准配置
    常用工具类11-上传类
    常用工具类10-上传水印类
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/5924797.html
Copyright © 2011-2022 走看看