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. 【原】安装mongo的php插件

    http://pecl.php.net/package/mongo https://github.com/mongodb/mongo-php-driver/tarball/master 1. 安装mo ...

  2. 剑指Offer:面试题19——二叉树的镜像(java实现)

    问题描述: 操作给定的二叉树,将其变换为源二叉树的镜像. 二叉树结点定义为: public class TreeNode { int val = 0; TreeNode left = null; Tr ...

  3. 【SSM 2】spring常用注解

    声明:以下观点,纯依据个人目前的经验和理解,有不当之处,多指教! 一.基本概述 注解(Annotation):也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举 ...

  4. C# 操作pem 文件

    using Dscf.Bpl.InformationAuditBpl; using Dscf.Bpl.ProductBpl; using Dscf.Global.CommonAduit; using ...

  5. C#通过安全证书生成签名和验签辅助类

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...

  6. 深入理解JS异步编程四(HTML5 Web Worker)

    >Web Workers 是 HTML5 提供的一个javascript多线程解决方案,我们可以将一些大计算量的代码交由web Worker运行而不冻结用户界面. 一:如何使用Worker We ...

  7. 『GreenPlum系列』GreenPlum 4节点集群安装(图文教程)

      目标架构如上图   一.硬件评估 cpu主频,核数推荐CPU核数与磁盘数的比例在12:12以上Instance上执行时只能利用一个CPU核资源进行计算,推荐高主频 内存容量 网络带宽重分布操作 R ...

  8. delphi 10 seattle 中 解决IOS 9 限制使用HTTP 服务问题

    IOS 9 于17号早上正式开始推送,早上起来立马安装,这次升级包只有1G, 安装空间也大大降低(想起IOS 8 升级时,几乎把手机里面的东西删光了,满眼都是泪). 虽然安装后,网上几乎是铺天盖地的吐 ...

  9. error C2259: 'CException' : cannot instantiate abstract class

    vc6.0编译通过,VS2008则报错 解决方法: 把CException改为CUserException

  10. ArrayEasyFinish

    (1)Plus One 解题思路:模拟现实中做加法的方式,在个位加一,并考虑进位的情况.代码如下: public class Solution { public int[] plusOne(int[] ...