HDU4268 Alice and Bob(贪心+multiset)
Please pay attention that each card can be used only once and the cards cannot be rotated.
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.
一开始用了贪心以后想用alice的最小w从bob最小w开始选,答案当然错了,应该用alice的最小w去选bob尽可能大的w。用了两个for,超时,于是用multiset,让时间复杂度瞬间降低,应该变成O(n)了。
#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set> using namespace std; struct card
{
int h,w;
}; int cmp(card a,card b)
{
if(a.h==b.h)
{
return a.w<b.w;
}
return a.h<b.h;
} int main()
{
int k,m,q,t,p,n;
int T;
cin>>T;
while(T--)
{
int ans=;
card a[],b[];
multiset<int> ms;
multiset<int>::iterator it; cin>>n;
for(int i=;i<n;++i)
{
scanf("%d %d",&a[i].h,&a[i].w);
}
for(int i=;i<n;++i)
{
scanf("%d %d",&b[i].h,&b[i].w);
} sort(a,a+n,cmp);
sort(b,b+n,cmp); int i=,j=;
for(;i<n;++i)
{
while(j<n&&(a[i].h>=b[j].h))
{
ms.insert(b[j].w);
++j;
}
if(ms.empty())
{
continue;
} it=ms.upper_bound(a[i].w);
if(it==ms.begin())
{
continue;
}else
{
--it;
++ans;
ms.erase(it);
} }
cout<<ans<<endl; }
return ;
}
HDU4268 Alice and Bob(贪心+multiset)的更多相关文章
- HDU4268 Alice and Bob 【贪心】
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 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 贪心STL O(nlogn)
B - Alice and Bob Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- 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 ...
- Alice and Bob(mutiset容器)
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Alice and Bob HDU - 4268
Alice and Bob's game never ends. Today, they introduce a new game. In this game, both of them have N ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- 【转】Android图片加载神器之Fresco-加载图片基础[详细图解Fresco的使用]
Fresco简单的使用—SimpleDraweeView 百学须先立志—学前须知: 在我们平时加载图片(不管是下载还是加载本地图片…..)的时候,我们经常会遇到这样一个需求,那就是当图片正在加载时应该 ...
- Spket在Eclipse/MyEclipse下的安装和配置(图文教程)
一.安装Spket 第一种方法:网上更新方式 1.插件首页:http://www.spket.com2.插件名称:Spket IDE3.更新连接(Update Site):http://www.spk ...
- MySQL常用工具
- XPath具体解释
New Document 相关读书笔记.心得文章列表 一.结点类型 XPath中有七种结点类型:元素.属性.文本.命名空间.处理指令.凝视以及文档节点(或成为根节点). 文档的根节点即是文档结点:相应 ...
- SQL 32位还原位64位出现3154错误
1:首先检查新建数据库的路径是否正确. 2:勾选覆盖原有数据库. 3:新建查询,选择master.然后新建查询中进行如下直接对bak文件的操作. RESTORE DATABASE TestFROM D ...
- kickstart一键自动安装Linux系统
kickstart,无人值守,自动安装系统.本文介绍kickstart的用法. #安装系统的信息——可以参考 [root@larrywen pdf]# vim ~/anaconda-ks.cfg 第一 ...
- Cookie和Session专题
一.cookie机制和session机制的区别***************************************************************************** ...
- volley开源库乱码问题总结(持续更新)
之前Android开发一直用的是多层封装的Final框架.最近开始学习使用小巧的volley. 在使用该框架的过程中,出现了数次乱码问题,再次做以总结. 分别是返回数据乱码和提交参数乱码两个问题: 一 ...
- wampserver下打开phpMyAdmin出现403错误的问题解决方法
图1 图2 wamp下打开phpMyAdmin出现403错误的问题解决方法安装完wamp后打开其下的phpMyAdmin也就是路径http://localhost/phpmyadmin/ 出现[图一] ...
- 在Android上使用ZXing识别条形码/二维码
越来越多的手机具备自动对焦的拍摄功能,这也意味着这些手机可以具备条码扫描的功能.......手机具备条码扫描的功能,可以优化购物流程,快速存储电子名片(二维码)等. 本文使用ZXing 1.6实现条码 ...