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) ...
随机推荐
- Hadoop on Mac with IntelliJ IDEA - 5 解决java heap space问题
本文讲述在CentOS 6.5中提交作业到hadoop 1.2.1于reduce阶段遇到Error: java heap space错误导致作业重新计算的解决过程.解决办法适用Linux.Mac OS ...
- 工作一直没有进步怎么办?试试PDCA法则吧!
许多人在工作或者学习的时候,总是会发现自己过了一段时间以后,全然没有不论什么进步.或者进步很之少. 而对于每个渴望让自己变得更好的人来说.是一件很令人苦恼的事情,今天我们就来谈一下工作和学习上,可实现 ...
- 从Windows 服务器通过sync向Linux服务器定时同步文件
本文解决的是Windows 下目录及文件向Linux同步的问题,Windows向 Windows同步的请参考:http://www.idcfree.com/article-852-1.html 环境介 ...
- javascript删除数组里的对象
Array.prototype.del = function(value) { //删除数组中指定的元素,返回新数组 function hasValue(array, value) { for(var ...
- sqldependency 支持的select
https://msdn.microsoft.com/library/ms181122.aspx 支持的 SELECT 语句 满足下列要求的 SELECT 语句支持查询通知: 必须显式说明 SEL ...
- 记录一些在VPS上折腾的东西
折腾这些东西,总是要经常借助搜索引擎找答案,找的次数多了,也就烦了,不想总是做重复工作. 所以把做过的一些事情记录一下,加深一下印象. 1.安装python2.7 VPS上面的太老了,之前安装的,过程 ...
- 安卓开发之使用viewpager+fragment实现滚动tab页
闲着.用viewpager+fragment实现了个滚动tab..轻拍,以后会陆续发先小东西出来..爱分享,才快乐.demo见附件.. package com.example.demo; import ...
- C#“同步调用”、“异步调用”、“异步回调”
本文将主要通过“同步调用”.“异步调用”.“异步回调”三个示例来讲解在用委托执行同一个“加法类”的时候的的区别和利弊. 首先,通过代码定义一个委托和下面三个示例将要调用的方法: ); //模拟该方法运 ...
- Tomcat中部署WEB项目的四种方法
对Tomcat部署web应用的方式总结,常见的有以下四种: 1.[使用控制台部署] 访问Http://localhost:8080,并通过Tomcat Manager登录,进入部署界面即可. 2.[利 ...
- demo virdata 虚拟数据
$pageCurr = I('p',1); $start = ($pageCurr-1) * self::PAGE_RECORD_SCAN; $sort = I('sor ...