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 }



  • 相关阅读:
    教你在Linux用飞信(fetion)免费发短信
    date 和 hwclock 命令 (RTC用的着)
    同学会催生“恐聚族” 攀比成风成为炫耀展示会
    35款基于terminal的Linux应用
    探访山东各地旱情 田里麦苗用手一搓成粉末
    多城市近期将出台楼市限购细则 全面限购第三套
    Linux下刻录光盘—cdrecord
    RHEL 6教程:使用本地光盘做yum源
    RHEL6 root登陆问题
    初学者学习LINUX之困惑?方向迷失?GUI?
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8529948.html
Copyright © 2011-2022 走看看