hdu 4268 贪心 学习了STL的 set 方法
2012-09-10 11:22
309 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4268
今天学习了下set,STL真强大。将Alice的card标记为type = 1,Bob的card标记为0。将所
有的纸片按照h,w的升序排序,按照type的降序排序,也就是在相同情况下将Bob的纸片放
前面。然后将Bob的纸片的w插入set,贪心选取Alice比Bob的纸片w大一点的来覆盖
今天学习了下set,STL真强大。将Alice的card标记为type = 1,Bob的card标记为0。将所
有的纸片按照h,w的升序排序,按照type的降序排序,也就是在相同情况下将Bob的纸片放
前面。然后将Bob的纸片的w插入set,贪心选取Alice比Bob的纸片w大一点的来覆盖
#include<iostream> #include<algorithm> #include<cstdio> #include<set> using namespace std; const int maxn=200002; int t,n; struct node { int h,w,type; bool operator <(const node &b)const { if(h != b.h) return h < b.h; if(w != b.w) return w < b.w; return type < b.type; } } p[maxn]; int main() { cin>>t; while(t--) { int i,j,ans=0; cin>>n; multiset<int>s; for(i=0; i<n; i++) { scanf("%d%d",&p[i].h,&p[i].w); p[i].type=1; } for(i=n; i<2*n; i++) { scanf("%d%d",&p[i].h,&p[i].w); p[i].type=0; } sort(p,p+2*n); for(i=0;i<2*n;i++) { if(p[i].type) { if(!s.empty()) { if(*s.begin()>p[i].w) continue; multiset<int>::iterator it=s.upper_bound(p[i].w); it--; ans++; s.erase(it); } }else { s.insert(p[i].w); } } printf("%d\n",ans); } return 0; }
相关文章推荐
- HDU 1051 二维排序安排时间 (贪心||STL_set 水过)
- HDU 4268 Alice and Bob 贪心STL O(nlogn)
- [HDU 4268](长春Online 1002) set+map + 贪心
- [HDU 4268](长春Online 1002) set+map + 贪心
- 贪心,STL,multiset(Alice and Bob,HDU 4268)
- HDU 4268 Alice and Bob(贪心+STL)
- Alice and Bob----HDU_4268----贪心+STL
- hdu 4268 Alice and Bob(STL贪心)
- HDU 4268 Alice and Bob(贪心+STL)
- hdu 4268 贪心+set lower_bound用法
- hdu 4268 贪心+set lower_bound用法
- HDU 4268-Alice and Bob( STL: set)
- C++学习 STL之set使用方法小结
- HDU-4989-Summary(STL之set)
- HDU 4268 Alice and Bob(贪心+数据结构)
- STL中的set使用方法详细!!!!
- 今天学习时看到Intent的setResult方法,不太懂。于是百度了一下
- C++ 标准模板库STL set 使用方法与应用介绍(一)
- hdu2072——单词数(STL,set)
- oc学习笔记-set和get函数 基础(Foundation)面向对象之封装方法