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 ...
随机推荐
- Numpy 常用函数
保存文件i3 = eye(3) 创建一个3*3 的单位矩阵savetxt('eye.txt',i3) #保存矩阵 读取文件c,v=np.loadtxt('data.csv', delimiter=', ...
- NavMesh KeyNote
[NavMesh KeyNote] 1.NavMesh.CalculatePath(srcPos, desPos) 若srcPos,desPos相等,则CalculatePath返回false. 2. ...
- git实用操作21条
1.建空目录 mkdir e:\gg 2.把该目录变成仓库 git init //发现当前目录下多了一个.git 3.新建文件readme.txt 4.添加文件到仓库 git add readm ...
- VB 共享软件防破解设计技术初探(一)
VB 共享软件防破解设计技术初探(一) ×××××××××××××××××××××××××××××××××××××××××××××× 其他文章快速链接: VB 共享软件防破解设计技术初探(二)http ...
- np.identity()
二.np.identity()这个函数和之前的区别在于,这个只能创建方阵,也就是N=M 函数的原型:np.identity(n,dtype=None) 参数:n,int型表示的是输出的矩阵的行数和列数 ...
- Extjs面板和布局初探
面板相当于一张干净的白纸,如果直接在上面添加内容,将很难控制面板中内容的显示位置,面板元素越多就越显得凌乱,所以需要在面板上划分不同的区域,将面板内容展示到希望的位置上.ExtJS通过提供多种布局类来 ...
- 【原创】Silverlight之TextBox的LostFocus、GotFocus事件
<TextBox x:Name="txtCount" Width="200" Height="35" GotFocus="t ...
- CookiesHelper
/// <summary> ///CookiesHelper 的摘要说明 /// </summary> public class CookiesHelper { public ...
- python性能测试大致计划
hi guy: 如果注意到创建时间,那就对了.这份文章,是我学习Python一个月以后动手写的. 写下这份计划以后,只完成了第一步,其中磕磕绊绊编写代码的过程,很大一部分时间是完全用txt写的 ...
- winsock select 学习代码(1)
// SelectCli.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <winsock2.h> #incl ...