B - Alice and Bob

Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 题意:10W个数据,A有n张牌,B有n张牌,然后如果a.x>=b.x&&a.y>=b.y 那么A就可以覆盖B
然后问你最多覆盖多少张
题解:暴力非常好想,O(n^2)跑一发就是,但是会T
那么我们就二分查找,或者用STL就好

multiset<int> myset;
multiset<int>::iterator it;
const int maxn=200000;
struct node
{
int x,y;
bool operator<(const node& b)const
{
return x<b.x;
}
}a[maxn],b[maxn];
int main()
{
int sec,n;
scanf("%d",&sec);
for(int z=1;z<=sec;z++)
{
myset.clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
for(int i=1;i<=n;i++)
scanf("%d%d",&b[i].x,&b[i].y);
sort(a+1,a+1+n);//按x从小到大排序
sort(b+1,b+1+n);//按x从小到大排序
int j=1;int ans=0;//j是一个指向B数组位置的指针
for(int i=1;i<=n;i++)
{
while(j<=n&&b[j].x<=a[i].x)
{
myset.insert(b[j].y);
j++;
}
it=myset.upper_bound(a[i].y);
if(myset.size()>0&&it!=myset.begin())it--;
if(myset.size()>0&&(*it)<=a[i].y)
{
ans++;
myset.erase(it);
}
}
printf("%d\n",ans);
}
return 0;
}
 

HDU 4268 Alice and Bob 贪心STL O(nlogn)的更多相关文章

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

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

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

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

  3. hdu 4268 Alice and Bob

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

  4. hdu 4268 Alice and Bob(贪心+multiset)

    题意:卡牌覆盖,每张卡牌有高(height)和宽(width).求alice的卡牌最多可以覆盖多少bob的卡牌 思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖. #include<ios ...

  5. HDU 4268 Alice and Bob set用法

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4268 贪心思想,用set实现平衡树,但是set有唯一性,所以要用 multiset AC代码: #i ...

  6. Alice and Bob(贪心HDU 4268)

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

  7. hdu 4111 Alice and Bob 记忆化搜索 博弈论

    Alice and Bob Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. hdu 3660 Alice and Bob's Trip(树形DP)

    Alice and Bob's Trip Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. HDU 5054 Alice and Bob(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5054 Problem Description Bob and Alice got separated ...

随机推荐

  1. Linux下C程序的反汇编【转】

    转自:http://blog.csdn.net/u011192270/article/details/50224267 前言:本文主要介绍几种反汇编的方法. gcc gcc的完整编译过程大致为:预处理 ...

  2. MySQL 5.7以后怎么查看索引使用情况?

    MySQL 5.7以后怎么查看索引使用情况? 0.在sys库中查看没用的索引 root@localhost [sys]>select * from schema_unused_indexes; ...

  3. [NOI2014]购票 「树上斜率优化」

    首先易得方程,且经过变换有 $$\begin{aligned} f_i &= \min\limits_{dist_i - lim_i \le dist_j} \{f_j + (dist_i - ...

  4. Django-自动HTML转义

    一.自动HTML转义 从模板生成HTML时,总会有变量包含影响最终HTML的字符风险,例如,考虑这个模板的片段: Hello, {{ name }} 起初,这是一种显示用户名的无害方式,但考虑用户输入 ...

  5. 03.JavaScript简单介绍

    一.JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEase.(客户端执行的语言) N ...

  6. 28 Data Race Detector 数据种类探测器:数据种类探测器手册

    Data Race Detector 数据种类探测器:数据种类探测器手册 Introduction Usage Report Format Options Excluding Tests How To ...

  7. python基础--subprocess模块

    可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen*          --废弃 popen2.*           --废弃 commands.* ...

  8. python基础--shutil模块

    shutil模块提供了大量的文件的高级操作. 特别针对文件拷贝和删除,主要功能为目录和文件操作以及压缩操作.对单个文件的操作也可参见os模块. 注意 即便是更高级别的文件复制函数(shutil.cop ...

  9. 查找sqlserver数据库中,查询某值所表名和字段名

    有时候我们想通过一个值知道这个值来自数据库的哪个表以及哪个字段,通过一个存储过程实现的.只需要传入一个想要查找的值,即可查询出这个值所在的表和字段名. 前提是要将这个存储过程放在所查询的数据库. CR ...

  10. const分别在C和C++语言里的含义和实现机制

    const的含义        简单地说:const在c语言中表示只读的变量,而在c++语言中表示常量. C语言 const是constant的缩写,是恒定不变的意思,也翻译为常量,但是很多人都认为被 ...