hdu 4268 Alice and Bob(贪心)
来源:互联网 发布:fc2免费视频域名 编辑:程序博客网 时间:2024/05/17 04:44
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4268
/* 贪心,先对高度排序(升序),接着宽度也排序(升序),接下来对于Alice的每个卡找到Bob所有 符合条件的卡片宽度最小的那个(因为高度已经符合了)。*/#include<iostream>#include <stdio.h>#include<string.h>#include<algorithm>#include <set>using namespace std;const int N=100010;struct node{ int x,y,t; friend bool operator<(const node &a,const node &b){ if(a.x ==b.x && a.y == b.y) return a.t>b.t; return a.x< b.x || (a.x == b.x&& a.y < b.y); }};multiset<int> S;node a[N<<1];const int Inf=1<<31;int T,n;int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0;i<n<<1;i++) scanf("%d%d",&a[i].x,&a[i].y); for(int i=0;i<n;i++) a[i].t=0; for(int i=n;i<n<<1;i++) a[i].t=1; sort(a,a+2*n); //for(int i = 0;i <n<<1;i++) // printf("%d %d %d\n",a[i].x,a[i].y,a[i].t); S.clear(); int ans=0; for(int i=0;i<2*n;i++) { if(a[i].t==1)S.insert(a[i].y); else { if(!S.empty()){ if(*S.begin()<=a[i].y){ __typeof(S.begin())it=S.upper_bound(a[i].y); it--; ans++; S.erase(it); } } } } printf("%d\n",ans); } return 0;}
0 0
- hdu 4268 Alice and Bob (set+贪心)
- HDU 4268 Alice and Bob(贪心+数据结构)
- HDU 4268 Alice and Bob(贪心)
- hdu 4268 Alice and Bob(贪心)
- 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)
- HDU 4268-Alice and Bob-贪心
- hdu 4268 Alice and Bob(贪心)
- HDU 4268 Alice and Bob 贪心+set应用
- 【set+贪心】HDU 4268——Alice and Bob
- HDU 4268 Alice and Bob——STl upper_bound + 贪心
- hdu 4268 Alice and Bob矩形覆盖(贪心)
- HDU 4268 Alice and Bob(贪心+Multiset的应用)
- hdu 4268 Alice and Bob(贪心+multiset+二分)
- hdu(4054)Hexadecimal View
- 四 Gazebo学习总结之Gazebo的某些设置属性和主题订阅
- Hdu(4417)Super Mario
- hdu4004(二分+贪心)
- code人心弦1101
- hdu 4268 Alice and Bob(贪心)
- zoj(3549)
- hdu(4422)
- hdu(4438)
- hdu(1053)
- hdu(1082)
- 对*nix中inode的几点理解
- hdu(1515)
- hdu(1257)