设为首页 加入收藏

TOP

hdu 4268 Alice and Bob(multiset)
2015-07-20 17:36:35 来源: 作者: 【 】 浏览:2
Tags:hdu 4268 Alice and Bob multiset

?

题目大意:就是问你Alice的牌能覆盖Bob牌最多数量。牌不能翻转

思路:首先我们不分种类,把牌按高度排序,然后我们在依次判断牌的种类,如果是Bob的牌,我们就他牌的宽度放入multiset中,如果是Alice的牌就在multiset中找到宽度最大的那一张并删掉。

?

?

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         using namespace std; const int maxn=200005; struct Node { int h,w,id; }node[maxn]; bool cmp(Node t1,Node t2) { if(t1.h!=t2.h) return t1.h
        
          s; multiset
         
          ::iterator ite; int main() { int n,i,T; scanf(%d,&T); while(T--) { scanf(%d,&n); for(i=1;i<=2*n;i++) { scanf(%d%d,&node[i].h,&node[i].w); node[i].id=(i<=n); } sort(node+1,node+2*n+1,cmp); s.clear(); int sum=0; for(i=1;i<=2*n;i++) { if(node[i].id==0) s.insert(node[i].w); else { if(s.empty()||node[i].w<*(s.begin())) continue; ite=s.upper_bound(node[i].w); //查找 ite--; sum++; s.erase(ite); //删除 } } printf(%d ,sum); } return 0; } 
         
        
       
      
     
    
   
  


?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BEGINNING SHAREPOINT® 2013.. 下一篇POJ - 1743 Musical Theme (后缀..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)