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 }



  • 相关阅读:
    multi-task learning
    代码杂谈-python函数
    代码杂谈-or符号
    安装maven
    zsh
    mint linux的几个问题
    [软件] Omnigraffle
    无梯度优化算法
    根据pdf文件获取标题等信息
    计算广告-GD广告
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8529948.html
Copyright © 2011-2022 走看看