http://acm.hdu.edu.cn/showproblem.php?pid=4268

A想用手里的牌尽量多地覆盖掉B手中的牌..



牌有h和w



问A手中的牌最多能覆盖B多少张牌

iterator lower_bound( const key_type &key ): 返回一个迭代器,指向键值>= key的第一个元素。

iterator upper_bound( const key_type &key ):返回一个迭代器,指向键值> key的第一个元素。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include<set>
using namespace std;
struct S
{
int a,b,c;
}p[200010];
int cmp(S M,S N)
{
if(M.a!=N.a) return M.a<N.a;
if(M.b!=N.b) return M.b<N.b;
return M.c>N.c;
}
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&p[i].a,&p[i].b),
p[i].c=0;
for(int i=n;i<2*n;i++)
scanf("%d%d",&p[i].a,&p[i].b),
p[i].c=1;
sort(p,p+2*n,cmp);
int ans=0;
set<int> s;
for(int i=0;i<2*n;i++)
{
if(p[i].c)
s.insert(p[i].b);
else
if(!s.empty()&&*s.begin()<=p[i].b)
{
set <int>::iterator it=s.upper_bound(p[i].b);
it--;
ans++;
s.erase(it);
}
}
printf("%d\n",ans);
}
}

hdu 4268 贪心+set lower_bound用法的更多相关文章

  1. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

  2. HDU 4268 Alice and Bob set用法

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

  3. Alice and Bob(贪心HDU 4268)

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

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

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

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

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

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

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

  7. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  8. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

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

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

随机推荐

  1. 树莓派Zero W GPIO控制

    作者:陈拓 chentuo@ms.xab.ac.cn 2018.06.09/2018.07.05 0.  概述 本文介绍树莓派 Zero W的GPIO控制,并用LED看效果. 0.1 树莓派GPIO编 ...

  2. 吴裕雄 实战python编程(3)

    import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com'html = requests.get(url)sp ...

  3. Spinnaker 介绍

    功能: 无论目标环境如何,Spinnaker 部署优势始终如一,它的功能如下: 通过灵活和可配置 Pipelines,实现可重复的自动化部署: 提供所有环境的全局视图,可随时查看应用程序在其部署 Pi ...

  4. mogodb查询

    Find: {$and: [ {"MethodName":"CommLogin"} ,{"CreateTime":{$gte:"2 ...

  5. luoguP1080 国王游戏 (贪心+高精度)

    题目链接:https://www.luogu.org/problemnew/show/P1080 参考:https://www.luogu.org/problemnew/solution/P1080 ...

  6. C/C++堆、栈及静态数据区详解

    转自:https://www.cnblogs.com/hanyonglu/archive/2011/04/12/2014212.html  做略微修改 C/C++堆.栈及静态数据区详解   本文介绍C ...

  7. day9:vcp考试

    Q161. An administrator wants to select a Host Power Management Policy for an ESXi 6.x host that will ...

  8. iOS 代码调试

    僵尸对象导致crash(Thread 1:EXC_BAD_ACCESS(code=EXC_I386_GPFLT)),需要给位release模式,debug模式不打印内存地址 https://blog. ...

  9. js variable 变量

    局部作用域 由于JavaScript的变量作用域实际上是函数内部,我们在for循环等语句块中是无法定义具有局部作用域的变量的: 'use strict'; function foo() { for ( ...

  10. springMVC使用@RequestParam用于处理简单类型的绑定

    使用@RequestParam常用于处理简单类型的绑定. value:参数名字,即入参的请求参数名字,如value=“item_id”表示请求的参数区中的名字为item_id的参数的值将传入: req ...