• 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 }
  • 相关阅读:
    第一个android App, hello world
    chrome网页重定向
    自动获取MyEcilipse注册名和注册码的方法
    jsp中两种include的区别【转】
    Eclipse中web项目部署至Tomcat【转】
    JAVA EE中session的理解
    JavaBean,POJO,VO,DTO的区别和联系
    Linux下apache+phppgadmin+postgresql安装配置
    Linux下apache+phppgadmin安装配置
    linux下jdk和tomcat的安装配置
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10885587.html
Copyright © 2020-2023  润新知