hdu 4268 Alice and Bob
Alice and Bob
Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 1
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem 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
2
1 2
3 4
2 3
4 5
3
2 3
5 7
6 8
4 1
2 5
3 4
Sample Output
1
2
题意:两组卡片,第一组的某一张卡片的长并且宽大于等于第二组某一张卡片的长和宽(x,y), 加1;
先sort排序下,利用multiset去存第二组的y,multiset容器可以存相同的元素
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
#include<vector>
//#define INF 0x3f3f3f3f
#define N 100005
typedef long long ll;
using namespace std;
struct node{
int x;
int y;
}a[N],b[N];
bool cmp(node aa,node bb){
if(aa.x==bb.x){
return aa.y<bb.y;
}
else
return aa.x<bb.x;
}
int main()
{
int t,n;
scanf("%d",&t);
int i,j;
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a,a+n,cmp);
for(i=;i<n;i++)
scanf("%d%d",&b[i].x,&b[i].y);
sort(b,b+n,cmp);
multiset<ll>st;
multiset<ll>::iterator it;
int ans=;
st.clear();
j=;
for(i=;i<n;i++){
while(a[i].x>=b[j].x&&j<n){
st.insert(b[j].y);
j++;
}
if(st.empty())
continue;
it=st.upper_bound(a[i].y);
if(it!=st.begin())
{
it--;
ans++;
st.erase(it);
}
}
printf("%d\n",ans);
}
}
hdu 4268 Alice and Bob的更多相关文章
- 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 贪心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 set用法
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4268 贪心思想,用set实现平衡树,但是set有唯一性,所以要用 multiset AC代码: #i ...
- hdu 4268 Alice and Bob(贪心+multiset)
题意:卡牌覆盖,每张卡牌有高(height)和宽(width).求alice的卡牌最多可以覆盖多少bob的卡牌 思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖. #include<ios ...
- 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 ...
- hdu 4111 Alice and Bob(中档博弈题)
copy VS study 1.每堆部是1的时候,是3的倍数时输否则赢: 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢: 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶 ...
随机推荐
- MyBatis环境配置
<settings> <!-- 使全局的映射器启用或禁用缓存. --> <setting name="cacheEnabled" value=&quo ...
- VBS数组
定义一个数组: dim a(3).这里要注意在VBS里面数组不像其他的例如C,C#,JAVA等数组用[]作为数组标志.VBS采用的是().还需要注意的是,这里定义的数组包含a(0),a(1),a(2) ...
- Fragment一些问题
1.使用fragment静态加载,当需要替换的时候使用replace方式是无效的....... 2.replace的容器如果是线性布局,那么将会出现之前的页面残留的情况,正确做法是使用FrameLay ...
- 创建一个swift项目
笔者认为你已经有了oc的开发基础,流程是一样的,选择开发语言为swift即可.这里主要说明一下一些常用的配置: 一般我们不使用XIB和storyboard,所以在系统自动创建的文件中删除main.st ...
- PHP基于数组的分页函数(核心函数array_slice())
关于数组的分页函数,用数组进行分页的好处是可以方便的进行联合多表查询,只需要将查询的结果放在数组中就可以了以下是数组分页的函数,函数page_array用于数组的分页,函数show_array用于分页 ...
- js动态生成input指定My97DatePicker时间问题
js生成的input指定onclick时间: 以下1.2为错误: onclick="WdatePicker()"; onclick=WdatePicker(); 若指定到windo ...
- js节点属性
在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType :节点的类 ...
- set QUOTED_IDENTIFIER ON事故记录
作业执行失败: 看了一下执行脚本 delete top(8000) from "interface"."完成" where loggid in( selec ...
- 使用Trello实现敏捷项目管理
使用Trello实现敏捷项目管理 作者 侯伯薇 发布于 五月 24, 2012 | 1 讨论 新浪微博腾讯微 ...
- Web开发新时代
Web1.0===主流技术:HTML+CSS Web2.0===主流技术:Ajax(Javascript/DOM/异步数据请求) Web3.0===主流技术:HTML5+CSS3 HTML5亮点:Ca ...