HDU 4268 Alice and Bob 贪心STL O(nlogn)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Please pay attention that each card can be used only once and the cards cannot be rotated.
Input
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
Sample Input
2
1 2
3 4
2 3
4 5
3
2 3
5 7
6 8
4 1
2 5
3 4
Sample Output
multiset<int> myset;
multiset<int>::iterator it;
const int maxn=200000;
struct node
{
int x,y;
bool operator<(const node& b)const
{
return x<b.x;
}
}a[maxn],b[maxn];
int main()
{
int sec,n;
scanf("%d",&sec);
for(int z=1;z<=sec;z++)
{
myset.clear();
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
for(int i=1;i<=n;i++)
scanf("%d%d",&b[i].x,&b[i].y);
sort(a+1,a+1+n);//按x从小到大排序
sort(b+1,b+1+n);//按x从小到大排序
int j=1;int ans=0;//j是一个指向B数组位置的指针
for(int i=1;i<=n;i++)
{
while(j<=n&&b[j].x<=a[i].x)
{
myset.insert(b[j].y);
j++;
}
it=myset.upper_bound(a[i].y);
if(myset.size()>0&&it!=myset.begin())it--;
if(myset.size()>0&&(*it)<=a[i].y)
{
ans++;
myset.erase(it);
}
}
printf("%d\n",ans);
}
return 0;
}
HDU 4268 Alice and Bob 贪心STL O(nlogn)的更多相关文章
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形.矩形不可旋转.问你Alice最多能覆盖Bo ...
- hdu 4268 Alice and Bob(multiset|段树)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 4268 Alice and Bob
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- hdu 4268 Alice and Bob(贪心+multiset)
题意:卡牌覆盖,每张卡牌有高(height)和宽(width).求alice的卡牌最多可以覆盖多少bob的卡牌 思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖. #include<ios ...
- 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 4111 Alice and Bob 记忆化搜索 博弈论
Alice and Bob Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 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 ...
- HDU 5054 Alice and Bob(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5054 Problem Description Bob and Alice got separated ...
随机推荐
- nginx配置location总结及rewrite规则写法【转】
转自 nginx配置location总结及rewrite规则写法 | Sean's Noteshttp://seanlook.com/2015/05/17/nginx-location-rewrite ...
- C# 去除文件非法字符名
string resultFileName = MD5Encrypt(NavigateUrl).Replace("=",string.Empty) + ".txt&quo ...
- JS实现逼真的雪花飘落特效
逼真的雪花飘落特效 效果图: 图片素材 : --> ParticleSmoke.png 代码如下,复制即可使用: <!doctype html> <html> <h ...
- B树 B+树 红黑树
B-Tree(B树) 具体讲解之前,有一点,再次强调下:B-树,即为B树.因为B树的原英文名称为B-tree,而国内很多人喜欢把B-tree译作B-树,其实,这是个非常不好的直译,很容易让人产生误解. ...
- KDE 下 U 盘挂载失败
重装完 KDE 后发现在 dolphin 中无法挂载 U 盘了,提示 unable to authenticate.但是用 udisksctl 却可以挂载: yyc@TDesk run > ud ...
- codis+redis 集群搭建管理
Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别 (不支持的命令列表), 上层应用可以像使 ...
- python开发学习-day13(js、jQuery)
s12-20160409-day13 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- codeforces 286 E. Ladies' Shop (FFT)
E. Ladies' Shop time limit per test 8 seconds memory limit per test 256 megabytes input standard inp ...
- 基于 SSH 框架的 Criteria 和 DetachedCriteria 多条件查询
Hibernate 定义了 CriteriaSpecification 接口规范用来完成面向对象的条件查询,Criteria 和 DetachedCriteria 就是 CriteriaSpecifi ...
- .NET Runtime version 2.0.50727.xxx 执行引擎错误。 (Fatal Execution Engine Error)
如题问题困扰本人良久. 尝试VS2005.VS2008.VS2010均出现过次问题. 主要现象: 1. Window设计器会崩溃,直接挂掉.(当逐条注释掉一些静态构造函数内的代码是情况好转) 2. 发 ...