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

    js-yui2-2.9.0-10.fc24.noarch.rpm 2016-09-25 07:06 1.2M fedora Mirroring Project js-yui2-jenkins-2.9. ...

  2. MySQL异步复制、半同步复制详解

    MySQL数据复制的原理图大致如下: 从上图我们可以看出MySQL数据库的复制需要启动三个线程来实现: 其中1个在主服务器上,另两个在从服务器上.当发出START SLAVE时,从服务器创建一个I/O ...

  3. textarea保留换行和空格

    <style> pre {white-space: pre-wrap;} </style> //替换textare <pre class="feedback_q ...

  4. Android 抽屉导航

    原文地址 http://developer.android.com/training/implementing-navigation/nav-drawer.html 创建抽屉导航 导航抽屉是在 屏幕左 ...

  5. 一、Vue入门

    vue官网:https://cn.vuejs.org/ 学习路线:VueJs2.0建议学习路线 在浏览器上安装 Vue Devtools工具 1.vue入门 <script src=" ...

  6. vue总结05 过渡--状态过渡

    状态过渡 Vue 的过渡系统提供了非常多简单的方法设置进入.离开和列表的动效.那么对于数据元素本身的动效呢,比如: 数字和运算 颜色的显示 SVG 节点的位置 元素的大小和其他的属性 所有的原始数字都 ...

  7. table中的td等长(不随内容大小变化)

    使用的table时候发现td的长度是随着内容的大小而变化的,但是有的时候我们不希望这样.想要td等长可以在 tbale中加上         style=“table-layout:fixed”   ...

  8. Java @SuppressWarnings

    @SuppressWarnings() 注解以@开头可以接受参数 @SuppressWarnings("unchecked") 不受检查的警告信息应该被抑制 //: holding ...

  9. HDU 3613 Best Reward(扩展KMP求前后缀回文串)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3613 题目大意: 大意就是将字符串s分成两部分子串,若子串是回文串则需计算价值,否则价值为0,求分割 ...

  10. Jenkins+Docker持续集成

    本节内容: Jenkins介绍 安装部署Jenkins Jenkins构建maven风格的job Jenkins邮件通知设置 Sonar Jenkins与Docker结合 一.Jenkins介绍 Je ...