HDU 4268 Alice and Bob (贪心)
2014-09-25 21:23
519 查看
对于 A中的 每一个扑克牌 在 x 可以覆盖的 范围内。 应该保证 被覆盖的 y尽量大。 这样 才是不浪费 y的。 并且 能够保证 后面的 A的 x更大的时候
出现 y 很小的时候 可以 覆盖 那些 x 小 并且 y 相对较小的。 这个思想很好的。
出现 y 很小的时候 可以 覆盖 那些 x 小 并且 y 相对较小的。 这个思想很好的。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <algorithm> #include <fstream> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <vector> #include <cmath> #include <iomanip> typedef long long LL; typedef unsigned long long LLU; const double PI=acos(-1.0); using namespace std; #define MAXN 100000+10 struct card{ int x,y; friend bool operator < (card a, card b){ if(a.x != b.x) return a.x < b.x; return a.y < b.y; } }; card a[MAXN],b[MAXN]; int main (){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d%d",&a[i].x, &a[i].y); for(int i = 0; i < n; i++) scanf("%d%d",&b[i].x, &b[i].y); sort(a,a+n); sort(b,b+n); multiset <int> s; int p = 0; int ans = 0; for(int i = 0; i < n; i++){ while(p < n && b[p].x <= a[i].x){ s.insert(b[p].y); p++; } if(s.size() >= 1){ multiset <int> ::iterator it = s.lower_bound(a[i].y); if(it == s.end()) it--; if(it != s.begin() && (*it) > a[i].y){ it--; } if((*it) <= a[i].y){ s.erase(it); ans++; } } } printf("%d\n",ans); } return 0; }
相关文章推荐
- hdu 4268 Alice and Bob(lower_bound+贪心)
- hdu 4268 Alice and Bob(贪心+multiset+二分)
- HDU 4268-Alice and Bob-贪心
- hdu 4268 Alice and Bob(贪心+multiset)
- hdu 4268 Alice and Bob(STL贪心)
- 贪心+multiset · HDU - 4268 ·Alice and Bob
- HDU 4268 Alice and Bob (set+贪心)
- HDU 4268 Alice and Bob——STl upper_bound + 贪心
- HDU 4268 Alice and Bob(贪心+STL)
- hdu 4268 Alice and Bob(贪心)
- 【set+贪心】HDU 4268——Alice and Bob
- HDU 4268 Alice and Bob(贪心)
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
- HDU 4268 Alice and Bob [贪心]
- Alice and Bob----HDU_4268----贪心+STL
- HDU 4268 Alice and Bob 贪心STL O(nlogn)
- hdu 4268 Alice and Bob矩形覆盖(贪心)
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
- Alice and Bob(贪心HDU 4268)
- HDU 4268 Alice and Bob(贪心)