Alice and Bob

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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
题意:两组卡片,第一组的某一张卡片的长并且宽大于等于第二组某一张卡片的长和宽(x,y), 加1;
先sort排序下,利用multiset去存第二组的y,multiset容器可以存相同的元素
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
#include<vector>
//#define INF 0x3f3f3f3f
#define N 100005
typedef long long ll;
using namespace std;
struct node{
int x;
int y;
}a[N],b[N];
bool cmp(node aa,node bb){
if(aa.x==bb.x){
return aa.y<bb.y;
}
else
return aa.x<bb.x;
}
int main()
{
int t,n;
scanf("%d",&t);
int i,j;
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a,a+n,cmp);
for(i=;i<n;i++)
scanf("%d%d",&b[i].x,&b[i].y);
sort(b,b+n,cmp);
multiset<ll>st;
multiset<ll>::iterator it;
int ans=;
st.clear();
j=;
for(i=;i<n;i++){
while(a[i].x>=b[j].x&&j<n){
st.insert(b[j].y);
j++;
}
if(st.empty())
continue;
it=st.upper_bound(a[i].y);
if(it!=st.begin())
{
it--;
ans++;
st.erase(it);
}
}
printf("%d\n",ans);
}
}

hdu 4268 Alice and Bob的更多相关文章

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

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

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

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

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

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

  4. HDU 4268 Alice and Bob set用法

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

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

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

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

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

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

  8. HDU 5054 Alice and Bob(数学)

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

  9. hdu 4111 Alice and Bob(中档博弈题)

    copy VS study 1.每堆部是1的时候,是3的倍数时输否则赢: 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢: 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶 ...

随机推荐

  1. 全面了解 Linux 服务器 - 1. 查看 Linux 服务器的 CPU 详细情况

    1. 查看 Linux 服务器的 CPU 详细情况 判断依据: 具有相同的 core id 的 CPU 是同意个 core 超线程. 具有相同的 physical id 的 CPU 是同一个 CPU ...

  2. System.TypeInitializationException: The type initializer for 'Mono.Unix.Native.Stdlib' threw an exception.

    08-31 17:02:03: ### DEBUG ##########################System.TypeInitializationException: The type ini ...

  3. study topics

    永远不变的东西,原理 study roadmap: 1.user space: tizen power manager => suspend/resume or runtime? android ...

  4. Spark JdbcRDD 简单使用

    package org.apache.spark.sql.sources import org.apache.spark.SparkContext import java.sql.{ResultSet ...

  5. HEAP CORRUPTION 错误

    一般是new一块内存过小,  在这个内存块上写入的内容过大, delete时出现的错误; 如: char* ptr = new char[2]; //申请了两个字节 *ptr = "1234 ...

  6. JMeter压力测试以文件的形式

    JMeter压力测试入门教程[图文] 1. 下载JMeter 2. 启动JMeter 3. 运行预准备 4. 运行 文章目录 Apache JMeter是Apache组织开发的基于Java的压力测试工 ...

  7. Multiverse in Doctor Strange // Multiverse在《神秘博士》

    关于<神秘博士>的制作内容 https://www.fxguide.com/quicktakes/bonus-luma-pictures-new-tools-for-doctor-stra ...

  8. JavaScript笔记杂谈篇(啥都有)

    二维码缩放比例以43PX的倍数缩放最为标准. NuGet相关管理http://www.cnblogs.com/dudu/archive/2011/07/15/nuget.html 学习笔记: http ...

  9. 0,SFDC 管理员篇 - 整体框架

    SFDC 框架布局, 通过以下分类我们可以了解Salesforce 每个云上所提供的功能和用途. ●销售云 Sales Cloud 销售自动化(Sales ForceAutomation,SFA)&a ...

  10. Thinkphp源码分析系列–开篇

    目前国内比较流行的php框架由thinkphp,yii,Zend Framework,CodeIgniter等.一直觉得自己在php方面还是一个小学生,只会用别人的框架,自己也没有写过,当然不是自己不 ...