HDU 4268 Alice and Bob(贪心+Multiset的应用)
题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形。矩形不可旋转。问你Alice最多能覆盖Bob的几个矩形?
思路:贪心,先依照h将Alice和Bob的矩形排序,对于Alice的每一个矩形。假设Bob的矩形的h小于Alice的h,将Bob的w插入到集合中。
然后,在集合中找到不大于Alice矩形d的最大的Bob的d,那么这样做肯定是最优的。
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<cstdlib>
- #include<iostream>
- #include<algorithm>
- #include<vector>
- #include<map>
- #include<queue>
- #include<stack>
- #include<string>
- #include<map>
- #include<set>
- #define eps 1e-6
- #define LL long long
- using namespace std;
- //const int maxn = 100 + 5;
- //const int INF = 0x3f3f3f3f;
- struct Card {
- int h, d;
- };
- Card ca[100010], cb[100010];
- bool cmp1(Card A, Card B) {
- return A.h < B.h;
- }
- multiset<int> ms;
- int main() {
- // freopen("input.txt", "r", stdin);
- int t; cin >> t;
- int n;
- while(t--) {
- cin >> n;
- ms.clear();
- for(int i = 0; i < n; i++) scanf("%d%d", &ca[i].h, &ca[i].d);
- for(int i = 0; i < n; i++) scanf("%d%d", &cb[i].h, &cb[i].d);
- sort(ca, ca+n, cmp1);
- sort(cb, cb+n, cmp1);
- int pos = 0, ans = 0;
- for(int i = 0; i < n; i++) {
- while(pos < n) {
- if(ca[i].h >= cb[pos].h) {
- ms.insert(cb[pos].d); pos++;
- }
- else break;
- }
- if(ms.empty()) continue;
- multiset<int>::iterator it = ms.upper_bound(ca[i].d);
- if(it != ms.begin()) {
- ans++; ms.erase(--it);
- }
- }
- cout << ans << endl;
- }
- return 0;
- }
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 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 ...
随机推荐
- c28---const
// // main.c // const关键字,节省内存空间,放在字符表里面, #include <stdio.h> int main(int argc, const char * ar ...
- LightOJ--1149--Factors and Multiples(二分图好题)
Factors and Multiples Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu ...
- Bone Collector(hdoj--2602--01背包)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Vue常用插件总结
Vue-router ----- 路由插件 Vue-loader-----webpack的加载器,允许您以称为单文件组件(SFC)的格式创作Vue组件 Vue-resource-----提供了使用 ...
- C# How to convert MessageBodyStream to MemoryStream?
通过WCF服务从数据库取文档数据时,返回的是Stream对象,在DevExpress的PDFViewer显示时,用PDFViewer.LoadDocunent(Stream stream);方法时,报 ...
- 读<<大数据时代>>的一些感想
第一次听说<<大数据时代>>这本书,是在网上看到的央视搞的一个2013中国好书评选活动推荐的25本“中国好书”的榜单中看到的.然后迅速上豆瓣上查看了一下对该书的评价,一看非常高 ...
- Sql Server 优化----SQL语句的执行方式与锁以及阻塞的关系
阻塞原因之一是不同的Session在访问同一张表的时候因为不兼容锁的原因造成的, 当前执行的SQL语句是否被阻塞(或者死锁),不仅跟当前表上的已有的锁有关,也会跟当前执行的SQL语句的执行方式有关 简 ...
- RedHat/CentOS 手动挂载磁盘
#创建挂载目录mkdir /mnt/sdamkdir /mnt/sdbmkdir /mnt/sdcmkdir /mnt/sddmkdir /mnt/sdemkdir /mnt/sdfmkdir /mn ...
- pwiz, a model generator
文档链接 pwiz is a little script that ships with peewee and is capable of introspecting an existing data ...
- -1.#IND000 &&图像类型转换
(1):float acos(float x) 参数x的范围为-1.0f到1.0f之间,返回值范围在0.0f到3.141592653f之间,值得注意的是:当x超出[-1.0f,1.0f]这个范围时此函 ...