Problem Description
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.
 
Input
The 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.
 
Output
For 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
 
Source

一开始用了贪心以后想用alice的最小w从bob最小w开始选,答案当然错了,应该用alice的最小w去选bob尽可能大的w。用了两个for,超时,于是用multiset,让时间复杂度瞬间降低,应该变成O(n)了。

 #include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set> using namespace std; struct card
{
int h,w;
}; int cmp(card a,card b)
{
if(a.h==b.h)
{
return a.w<b.w;
}
return a.h<b.h;
} int main()
{
int k,m,q,t,p,n;
int T;
cin>>T;
while(T--)
{
int ans=;
card a[],b[];
multiset<int> ms;
multiset<int>::iterator it; cin>>n;
for(int i=;i<n;++i)
{
scanf("%d %d",&a[i].h,&a[i].w);
}
for(int i=;i<n;++i)
{
scanf("%d %d",&b[i].h,&b[i].w);
} sort(a,a+n,cmp);
sort(b,b+n,cmp); int i=,j=;
for(;i<n;++i)
{
while(j<n&&(a[i].h>=b[j].h))
{
ms.insert(b[j].w);
++j;
}
if(ms.empty())
{
continue;
} it=ms.upper_bound(a[i].w);
if(it==ms.begin())
{
continue;
}else
{
--it;
++ans;
ms.erase(it);
} }
cout<<ans<<endl; }
return ;
}

HDU4268 Alice and Bob(贪心+multiset)的更多相关文章

  1. HDU4268 Alice and Bob 【贪心】

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. Alice and Bob(贪心HDU 4268)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  3. HDU 4268 Alice and Bob 贪心STL O(nlogn)

    B - Alice and Bob Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  4. HDU 4268 Alice and Bob(贪心+Multiset的应用)

     题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...

  5. hdu 4268 Alice and Bob(multiset|段树)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. hdu 4268 Alice and Bob

    Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  7. Alice and Bob(mutiset容器)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. 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 ...

  9. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. RFIDler - An open source Software Defined RFID Reader/Writer/Emulator

    https://www.kickstarter.com/projects/1708444109/rfidler-a-software-defined-rfid-reader-writer-emul h ...

  2. linux集群管理<转>

    云在根本上是由硬件和软件组成的,这些组件需要经常细心地维护.出现故障的硬件需要修理或更换:软件需要应用补丁.更新和升级:必须根据需求和潜在的安全威胁提前配置系统.应用程序开发人员可能觉得计算云很方便. ...

  3. IE下实现类似CSS3 text-shadow文字阴影的几种方法

    IE下实现类似CSS3 text-shadow文字阴影的几种方法 一.开始的擦边话 为了测试IE9浏览器,下午晃晃荡荡把系统换成window7的了.果然,正如网上所传言的一样,IE9浏览器确实不支持C ...

  4. CSS复合样式

    关于font OK,我们先从font来谈起. 如下一段代码: div{ font-size: 14px; font-family: '\5FAE\8F6F\96C5\9ED1'; font-weigh ...

  5. JavaScript创建Map对象(转)

    JavaScript 里面本身没有map对象,用JavaScript的Array来实现Map的数据结构. /* * MAP对象,实现MAP功能 * * 接口: * size()     获取MAP元素 ...

  6. PhoneGap+jQuery Mobile+Rest 访问远程数据

    最近研究Mobile Web技术.发现了一个好东西-PhoneGap! 发现用PhoneGap+jQuery Mobile是一个很完美的组合! 本实例通俗易懂.适合广大开发人群:高富帅.白富美.矮穷戳 ...

  7. [Express] Level 1: First Step

    Installing Express Let's start building our new Express application by installing Express. Type the ...

  8. ThinkPHP中pathinfo模式与URL重写

    Thinkphp中的pathinfo模式 http://serverName/appName/module/action/id/1/ pathinfo模式 在不考虑路由的情况下,第一个参数会被解析成模 ...

  9. linux下的十六进制编辑器---wxHexEdit

    ....其实wxHexEdit是一个跨平台的十六进制编辑器,支持windows,linux,mac. 之所以标题用linux...是因为windows下多数都用winhex,UE之类的编辑器,而lin ...

  10. MapReduce原理及其主要实现平台分析

    原文:http://www.infotech.ac.cn/article/2012/1003-3513-28-2-60.html MapReduce原理及其主要实现平台分析 亢丽芸, 王效岳, 白如江 ...