zoukankan      html  css  js  c++  java
  • Alice and Bob HDU

    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. 

    InputThe 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. 
    OutputFor 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

    爱丽丝和鲍勃的游戏永远不会结束。 今天,他们推出了一款新游戏。 在这场比赛中,他们两人分别拥有N张不同的矩形牌。 爱丽丝想用他的卡片来掩护鲍勃的。 如果A的高度不小于B并且A的宽度不小于B,则卡A可以覆盖卡B.作为最好的程序员,要求您计算Alice可以覆盖的鲍勃卡的最大数量。
    请注意,每张卡只能使用一次,卡不能旋转。

    通过这题学习了一个新的数据结构multiset

    这个数据结构完美的切合题目意思

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 #include<queue>
     5 #include<math.h>
     6 #include<set>
     7 using namespace std;
     8 
     9 struct node
    10 {
    11     int w,h;
    12 }a[100010],b[100010];
    13 int cmp(node c,node d)
    14 {
    15     return c.w<d.w;
    16 }
    17 multiset<int>m;
    18 multiset<int>::iterator it;
    19 
    20 int main() {
    21     int t;
    22     scanf("%d",&t);
    23     while(t--){
    24         int n;
    25         scanf("%d",&n);
    26         for (int i=0 ;i<n ;i++){
    27             scanf("%d%d",&a[i].w,&a[i].h);
    28         }
    29         for (int i=0 ;i<n ;i++){
    30             scanf("%d%d",&b[i].w,&b[i].h);
    31         }
    32         int ans=0;
    33         sort(a,a+n,cmp);
    34         sort(b,b+n,cmp);
    35         m.clear();
    36         for (int i=0 ,j=0 ; i<n ;i++){
    37             while(j<n&&a[i].w>=b[j].w) {
    38                 m.insert(b[j++].h);
    39             }
    40             if(m.empty()) continue;
    41             it = m.upper_bound(a[i].h);
    42             if(it != m.begin()) {
    43                 it--;
    44                 m.erase(it);
    45                 ans++;
    46             }
    47         }
    48         printf("%d
    ",ans);
    49     }
    50     return 0;
    51 }



  • 相关阅读:
    IIS: 必须输入密码手动设置密码同步后
    IIS操作控制类
    SQL对IP地址进行拆分
    HTTP_REFERER的工作方式[转贴]
    如何知道同服务器上都有哪些网站?
    简单判断临时表是否存在
    .NET 3.5 SP 1发布了
    Log Parser很好很强大的IIS日志分析工具
    遍历Request.ServerVariables
    06复杂查询(多数据库表)
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8529948.html
Copyright © 2011-2022 走看看