hdu 4268 贪心+set lower_bound用法
http://acm.hdu.edu.cn/showproblem.php?pid=4268
A想用手里的牌尽量多地覆盖掉B手中的牌..
牌有h和w
问A手中的牌最多能覆盖B多少张牌
iterator lower_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用法的更多相关文章
- hdu 4268 multiset+贪心
Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...
- HDU 4268 Alice and Bob set用法
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4268 贪心思想,用set实现平衡树,但是set有唯一性,所以要用 multiset AC代码: #i ...
- Alice and Bob(贪心HDU 4268)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 4268 Alice and Bob(贪心+multiset)
题意:卡牌覆盖,每张卡牌有高(height)和宽(width).求alice的卡牌最多可以覆盖多少bob的卡牌 思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖. #include<ios ...
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...
- HDU 4268 Alice and Bob 贪心STL O(nlogn)
B - Alice and Bob Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 4268 Alice and Bob(multiset|段树)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- conductor Workflow Metrics
Server Metrics conductor使用spectator收集指标.https://github.com/Netflix/spectator 名称 目的 标签 workflow_serve ...
- conductor介绍
https://netflix.github.io/conductor/ https://github.com/Netflix/conductor 编译版: https://jcenter.bintr ...
- SpringCloud组件和概念介绍1
一:什么是微服务(Microservice) 微服务英文名称Microservice,Microservice架构模式就是将整个Web应用组织为一系列小的Web服务.这些小的Web服务可以独立地编译及 ...
- MySql LeftJoin On 与 Where的差异
[MySql LeftJoin On 与 Where的差异] 存在两张表: 分别插入数据: 下面的语句一与语句二会产生不同的结果: 语句一: 结果: 语句二: 结果: 为什么会存在差异,这和on与wh ...
- Cannot create inner bean '(inner bean)#67f903b5' of typ
严重: Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error crea ...
- springboot 面向切面
@Aspect @Configuration public class AspectTest { @Pointcut("execution(public String xxx.xxx.xxx ...
- java的Map浅析
Map<K,V>是以键-值对存储的(key-value), 而Entry<K,V>是Map中的一个接口,Map.Entry<K,V>接口主要用于获取.比较 key和 ...
- java非常好用的读取文件的流的代码
学过java的都知道java中有非常多的读取文件流的操作.这个要回到javase的io操作了.io流说实话,初学者学的肯定会非常混乱,那么多流,什么输入流,输出流,什么文件流,什么字节流,等等.我在这 ...
- Url,HTTPUrlConnection(一)
package com.cmy.urlcon; import java.io.BufferedReader; import java.io.IOException; import java.io.In ...
- .NET中CORS跨域访问WebApi
我这里只写基本用法以作记录,具体为什么看下面的文章: http://www.cnblogs.com/landeanfen/p/5177176.html http://www.cnblogs.com/m ...