hdu 4268 Alice and Bob
来源:互联网 发布:二维码识别源码 编辑:程序博客网 时间:2024/05/22 14:31
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4268
题目大意:
Alice和Bob各有N(N<=100,000)张卡,卡有两个属性(w,h),如果A卡的这两个属性均不小于B卡的,则A卡可以覆盖B卡,求Alice最多可以盖Bob几张卡.
题目思路:
如果Alice的某张卡的h大于Bob的某些卡的h,那么可以知道Alice的这张卡应该盖这些卡中w值最大的且w值小于Alice的这张卡的w值(设为W).
假设Alice不盖可以盖的最大w值的那张卡,盖了一张小的(设为W‘),那么如果Alice有一张卡属性为h'和w'(h'>h,W'<w'<W),那么容易发现,如果之前盖了W,那么就可以多盖一张卡了.
通俗的来说就是要盖就盖能盖的最大卡.
代码:
#include <stdlib.h>#include <string.h>#include <stdio.h>#include <ctype.h>#include <math.h>#include <time.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <string>#include <iostream>#include <algorithm>using namespace std;#define ull unsigned __int64#define ll __int64//#define ll long long#define ls rt<<1#define rs ls|1#define lson l,mid,ls#define rson mid+1,r,rs#define middle l+r>>1#define INF 0x3F3F3F3F#define esp (1e-10)#define MOD 1000000007#define type int//const double pi=acos(-1.0);const int M=100000+5;#define clr(x,c) memset(x,c,sizeof(x))type min(type x,type y){return x<y? x:y;}type max(type x,type y){return x>y? x:y;}void swap(type& x,type& y){type t=x;x=y;y=t;}int T,cas=0;int n,m,ww[M<<1];struct node{ int h,w; void read(){ scanf("%d%d",&h,&w); ww[++m]=w; } bool operator < (const node &p) const { return h==p.h? w<p.w:h<p.h; }};node a[M],b[M];int bs(int key){ int l=1,r=m,mid; while(l<=r){ mid=middle; if(key>ww[mid]) l=mid+1; else if(key<ww[mid]) r=mid-1; else return mid; }return -1;}int mmax[M<<3],cnt[M<<1];void update(int l,int r,int rt,int p,int c){ if(l==r){ mmax[rt]= (cnt[l]+=c)? l:0; return; } int mid=middle; if(p<=mid) update(lson,p,c); else update(rson,p,c); mmax[rt]=max(mmax[ls],mmax[rs]);}int query(int l,int r,int rt,int L,int R){ if(L<=l && r<=R) return mmax[rt]; int mid=middle,ret=0; if(R<=mid) return query(lson,L,R); else if(mid<L) return query(rson,L,R); else return max(query(lson,L,mid),query(rson,mid+1,R));}void run(){ int i,j,k,ret=0; scanf("%d",&n),m=0; for(i=1;i<=n;i++) a[i].read(); for(i=1;i<=n;i++) b[i].read(); sort(ww+1,ww+m+1); //m=unique(ww+1,ww+m+1)-(ww+1); for(i=2,k=1;i<=m;i++) if(ww[i]!=ww[i-1]) ww[++k]=ww[i]; m=k; sort(a+1,a+n+1),sort(b+1,b+n+1); clr(mmax,0),clr(cnt,0); for(i=j=1;i<=n;i++){ while(j<=n && b[j].h<=a[i].h){ update(1,m,1,bs(b[j].w),1); j++; } k=query(1,m,1,0,bs(a[i].w)); if(k>0) ret++,update(1,m,1,k,-1); } printf("%d\n",ret);}int main(){ //freopen("1.in","r",stdin); //freopen("1.out","w",stdout); //preSof(); //run(); //while(~scanf("%d",&n)) run(); for(scanf("%d",&T),cas=1;cas<=T;cas++) run(); //system("pause"); return 0;}
- HDU 4268 - Alice and Bob
- hdu 4268 Alice and Bob
- hdu 4268 Alice and Bob
- hdu - 4268 - Alice and Bob
- HDU 4268 Alice and Bob
- hdu 4268 alice and bob
- hdu 4268 Alice and Bob
- hdu 4268 Alice and Bob
- HDU 4268 - Alice and Bob
- HDU 4268 Alice and Bob
- Alice and Bob HDU
- HDU 4268 Alice and Bob 贪
- ChangChun_1002 Alice and Bob (HDU 4268)
- hdu 4268 Alice and Bob (set+贪心)
- HDU 4268 Alice and Bob set用法
- HDU 4268 Alice and Bob(贪心+数据结构)
- HDU 4268 Alice and Bob(贪心)
- hdu 4268 Alice and Bob(贪心)
- 三门问题
- php +mysql 留言板 1
- 开始用java做ACM题一开始就遇到了困难
- php & mysql 留言版2
- php & mysql 留言板 3
- hdu 4268 Alice and Bob
- 消息处理(Message Handling)
- log4j配置详解
- php mysql 留言板 4
- QT中类的前向声明
- php & mysql (五)
- 浅议 Dynamic_cast 和 RTTI
- php +mysql 6
- hdu 4052 Adding New Machine