hdu 4268 Alice and Bob(贪心+multiset)
题意:卡牌覆盖,每张卡牌有高(height)和宽(width)。求alice的卡牌最多可以覆盖多少bob的卡牌
思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖。
#include<iostream>
#include<stdio.h>
#include<set>
#include<algorithm>
using namespace std; struct Node{
int h,w;
int flag;
}node[]; bool cmp(Node a,Node b){
if(a.h!=b.h)return a.h<b.h;//升序
if(a.w!=b.w)return a.w<b.w;//升序
return a.flag>b.flag;//降序
} multiset<int>mt;
multiset<int>::iterator it; int main(){
int t,n,i,ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=;i<=n;++i){
scanf("%d%d",&node[i].h,&node[i].w);
node[i].flag=;
}
for(i=n+;i<=*n;++i){
scanf("%d%d",&node[i].h,&node[i].w);
node[i].flag=;
}
sort(node+,node++*n,cmp);
mt.clear();
ans=;
for(i=;i<=*n;++i){
if(node[i].flag==)mt.insert(node[i].w);
else{
if(!mt.empty()){
it=mt.begin();
if(node[i].w>=(*it)){
++ans;
it=mt.upper_bound(node[i].w);//指向键值> key的第一个元素。
--it;//指向键值<= key的第一个元素。
mt.erase(it);
}
}
}
}
printf("%d\n",ans);
}
return ;
}
hdu 4268 Alice and Bob(贪心+multiset)的更多相关文章
- 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 ...
- 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 ...
随机推荐
- msp430入门学习43
msp430的其他十一 msp430入门学习
- msp430入门学习42
msp430的其他十 msp430入门学习
- Python入门--4--分之和循环
1.用ELIF比较省CPU: 第一种方法,使用if score = int(input('请输入你的分数:')) if (score <= 100) and (score >= 90): ...
- Yii 之视图数据块
控制器代码: public $layout = 'common'; public function actionStudent(){ $data = array('page_name'=>'St ...
- druid 的应用(密码加密),logback的应用
参考博客:https://github.com/yjmyzz/spring-mybatis-multidatasourcehttp://www.cnblogs.com/dream-to-pku/p/6 ...
- BB FlashBack pro导出AVI格式的配置参数
文件-->导出,选择AVI格式在选择AVI解码器中选择Cinepak Codec by Radius压缩质量:建议6~12%点击确定在AVI导出选项中选择帧速率:4帧每秒音频选择格式 11.02 ...
- luogu P3420 [POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...
- [Bzoj5043][Lydsy1709月赛]密码破译(按位dp)
5043: [Lydsy1709月赛]密码破译 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 477 Solved: 125[Submit][Sta ...
- [scrapy]Item Loders
Items Items就是结构化数据的模块,相当于字典,比如定义一个{"title":"","author":""},i ...
- add swapspace file on ubuntu.
https://askubuntu.com/questions/566745/allocate-swap-after-ubuntu-14-04-lts-installation ----------- ...