题意: Alice和Bob有n个长方形,有长度和宽度,一个矩形能够覆盖还有一个矩形的条件的是,本身长度大于等于还有一个矩形,且宽度大于等于还有一个矩形。矩形不可旋转。问你Alice最多能覆盖Bob的几个矩形?

思路:贪心,先依照h将Alice和Bob的矩形排序,对于Alice的每一个矩形。假设Bob的矩形的h小于Alice的h,将Bob的w插入到集合中。

然后,在集合中找到不大于Alice矩形d的最大的Bob的d,那么这样做肯定是最优的。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<iostream>
  6. #include<algorithm>
  7. #include<vector>
  8. #include<map>
  9. #include<queue>
  10. #include<stack>
  11. #include<string>
  12. #include<map>
  13. #include<set>
  14. #define eps 1e-6
  15. #define LL long long
  16. using namespace std;
  17.  
  18. //const int maxn = 100 + 5;
  19. //const int INF = 0x3f3f3f3f;
  20. struct Card {
  21. int h, d;
  22. };
  23.  
  24. Card ca[100010], cb[100010];
  25. bool cmp1(Card A, Card B) {
  26. return A.h < B.h;
  27. }
  28. multiset<int> ms;
  29.  
  30. int main() {
  31. // freopen("input.txt", "r", stdin);
  32. int t; cin >> t;
  33. int n;
  34. while(t--) {
  35. cin >> n;
  36. ms.clear();
  37. for(int i = 0; i < n; i++) scanf("%d%d", &ca[i].h, &ca[i].d);
  38. for(int i = 0; i < n; i++) scanf("%d%d", &cb[i].h, &cb[i].d);
  39. sort(ca, ca+n, cmp1);
  40. sort(cb, cb+n, cmp1);
  41. int pos = 0, ans = 0;
  42. for(int i = 0; i < n; i++) {
  43. while(pos < n) {
  44. if(ca[i].h >= cb[pos].h) {
  45. ms.insert(cb[pos].d); pos++;
  46. }
  47. else break;
  48. }
  49. if(ms.empty()) continue;
  50. multiset<int>::iterator it = ms.upper_bound(ca[i].d);
  51. if(it != ms.begin()) {
  52. ans++; ms.erase(--it);
  53. }
  54. }
  55. cout << ans << endl;
  56. }
  57. return 0;
  58. }

HDU 4268 Alice and Bob(贪心+Multiset的应用)的更多相关文章

  1. HDU 4268 Alice and Bob 贪心STL O(nlogn)

    B - Alice and Bob Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  2. hdu 4268 Alice and Bob(multiset|段树)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. hdu 4268 Alice and Bob

    Alice and Bob Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  4. hdu 4268 Alice and Bob(贪心+multiset)

    题意:卡牌覆盖,每张卡牌有高(height)和宽(width).求alice的卡牌最多可以覆盖多少bob的卡牌 思路:贪心方法就是找h可以覆盖的条件下找w最大的去覆盖. #include<ios ...

  5. HDU 4268 Alice and Bob set用法

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4268 贪心思想,用set实现平衡树,但是set有唯一性,所以要用 multiset AC代码: #i ...

  6. Alice and Bob(贪心HDU 4268)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. hdu 4111 Alice and Bob 记忆化搜索 博弈论

    Alice and Bob Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. 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 ...

  9. HDU 5054 Alice and Bob(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5054 Problem Description Bob and Alice got separated ...

随机推荐

  1. c28---const

    // // main.c // const关键字,节省内存空间,放在字符表里面, #include <stdio.h> int main(int argc, const char * ar ...

  2. LightOJ--1149--Factors and Multiples(二分图好题)

    Factors and Multiples Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu ...

  3. Bone Collector(hdoj--2602--01背包)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  4. Vue常用插件总结

    Vue-router ----- 路由插件 Vue-loader-----webpack的加载器,允许您以称为单文件组件(SFC)的格式创作Vue组件   Vue-resource-----提供了使用 ...

  5. C# How to convert MessageBodyStream to MemoryStream?

    通过WCF服务从数据库取文档数据时,返回的是Stream对象,在DevExpress的PDFViewer显示时,用PDFViewer.LoadDocunent(Stream stream);方法时,报 ...

  6. 读<<大数据时代>>的一些感想

    第一次听说<<大数据时代>>这本书,是在网上看到的央视搞的一个2013中国好书评选活动推荐的25本“中国好书”的榜单中看到的.然后迅速上豆瓣上查看了一下对该书的评价,一看非常高 ...

  7. Sql Server 优化----SQL语句的执行方式与锁以及阻塞的关系

    阻塞原因之一是不同的Session在访问同一张表的时候因为不兼容锁的原因造成的, 当前执行的SQL语句是否被阻塞(或者死锁),不仅跟当前表上的已有的锁有关,也会跟当前执行的SQL语句的执行方式有关 简 ...

  8. RedHat/CentOS 手动挂载磁盘

    #创建挂载目录mkdir /mnt/sdamkdir /mnt/sdbmkdir /mnt/sdcmkdir /mnt/sddmkdir /mnt/sdemkdir /mnt/sdfmkdir /mn ...

  9. pwiz, a model generator

    文档链接 pwiz is a little script that ships with peewee and is capable of introspecting an existing data ...

  10. -1.#IND000 &&图像类型转换

    (1):float acos(float x) 参数x的范围为-1.0f到1.0f之间,返回值范围在0.0f到3.141592653f之间,值得注意的是:当x超出[-1.0f,1.0f]这个范围时此函 ...