zoukankan      html  css  js  c++  java
  • HDU4268(贪心+multiset)

    Alice and Bob HDU - 4268

    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


    没能AC的代码,恳请各位大佬们帮我看看哪里出错了。

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <queue>
     4 #include <vector>
     5 #include<string.h>
     6 #include<map>
     7 #include<bits/stdc++.h>
     8 using namespace std;
     9 int n,m,t,x,y;
    10 struct node
    11 {
    12     int h,w;
    13     node(int a,int b){h=a,w=b;}
    14     friend bool operator<(node x,node y)
    15     {
    16         if(x.h!=y.h)
    17             return x.h<y.h;
    18         else if(x.w!=y.w)
    19             return x.w<y.w;
    20     }
    21 };
    22 int main()
    23 {
    24     scanf("%d",&n);
    25     while(n--)
    26     {
    27         multiset<node> s;
    28         multiset<node>::iterator it;
    29         int ans=0;
    30         scanf("%d",&m);
    31         for(int i=0;i<m;i++)
    32         {
    33             scanf("%d%d",&x,&y);
    34             node k(x,y);
    35             s.insert(k);
    36         }
    37         for(int i=0;i<m;i++)
    38         {
    39             scanf("%d%d",&x,&y);
    40             node k(x,y);
    41             if(s.lower_bound(k)!=s.end())
    42             {
    43                 it=s.lower_bound(k);
    44                 s.erase(it);
    45                 ans++;
    46             }
    47         }
    48         cout<<ans<<endl;
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    周4早上搜索引擎分析 crmim.com| MSCRM开发者之家
    Bat命令学习
    sqlserver日期函数
    ubunto应用软件
    sql for xml
    win7x64 连接oracle 客户端 vs 2010调试 提示“ORA12154: TNS: 无法解析指定的连接标识符 ”ORA06413 问题(转)
    CentOS Rsync服务端与Windows cwRsync客户端实现数据同步
    怎么引导2岁孩子洗手问题
    Libnfcinstallation
    Asterisk资料
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10885587.html
Copyright © 2011-2022 走看看