POJ 2464 Brownie Points II(树状数组||线段树)
来源:互联网 发布:淘宝网站建设合同 编辑:程序博客网 时间:2024/05/16 14:26
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
很久以前,用线段树做过。
题意有点悬乎:有一些点,Stan选择某个点,经过这个点画一条竖线,Ollie选择一个经过这条直接的点画了条横线。
Stan选一,三象限的点,Ollie选二、四象限的点。
Stan的策略是,自己画一条竖线之后,Ollie有很多种选择,在所有选择中,Stan能获得数目的最小值的最大值,而Ollie的选择便 是让自己越多越好。
http://poj.org/problem?id=2464
首先对于某个方向离散化,我是按x排序,将y离散化。
建立两个树状数组,表示竖线左边的点个数,右边的点个数
然后按x递增扫描一遍,预先先把所有点插入到右树中。
然后逐步更新左树和右树。
#include<iostream> #include<cstdio> #include<map> #include<cstring> #include<cmath> #include<vector> #include<algorithm> #include<set> #include<string> #include<queue> #define inf 1600005 #define M 40 #define N 200000 #define maxn 300005 #define eps 1e-12#define zero(a) fabs(a)<eps #define Min(a,b) ((a)<(b)?(a):(b)) #define Max(a,b) ((a)>(b)?(a):(b)) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define mem(a,b) memset(a,b,sizeof(a)) #define LL unsigned long long #define MOD 1000000007#define lson step<<1#define rson step<<1|1#define sqr(a) ((a)*(a)) #define Key_value ch[ch[root][1]][0] #define test puts("OK"); #define pi acos(-1.0)#define lowbit(x) ((-(x))&(x))#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std;struct Point{ int x,y; bool operator<(const Point p)const{ return x<p.x; }}p[N+5];int y[N],cnt;int l[N+5],r[N+5];int n;void Update(int *s,int x,int val){ for(int i=x;i<=cnt;i+=lowbit(i)) s[i]+=val;}int sum(int *s,int x){ int ret=0; for(int i=x;i>0;i-=lowbit(i)) ret+=s[i]; return ret;}int main(){ //freopen("in.txt","r",stdin); while(scanf("%d",&n)!=EOF&&n){ for(int i=0;i<n;i++){ scanf("%d%d",&p[i].x,&p[i].y); y[i]=p[i].y; } sort(p,p+n); sort(y,y+n); cnt=unique(y,y+n)-y; mem(l,0);mem(r,0); for(int i=0;i<n;i++) Update(r,lower_bound(y,y+cnt,p[i].y)-y+1,1); int Stan=-1,st=0; vector<int>Ollie; for(int i=1;i<=n;i++){ if(i==n||p[i].x!=p[i-1].x){ for(int j=st;j<i;j++) Update(r,lower_bound(y,y+cnt,p[j].y)-y+1,-1); int stan=-1,ollie=-1; for(int j=st;j<i;j++){ int pos=lower_bound(y,y+cnt,p[j].y)-y+1; int a=sum(r,cnt)-sum(r,pos)+sum(l,pos-1); int b=sum(l,cnt)-sum(l,pos)+sum(r,pos-1); if(b==ollie) stan=min(stan,a); else if(b>ollie) stan=a,ollie=b; } if(stan>Stan){ Stan=stan; Ollie.clear(); } if(stan==Stan) Ollie.pb(ollie); for(int j=st;j<i;j++) Update(l,lower_bound(y,y+cnt,p[j].y)-y+1,1); st=i; } } printf("Stan: %d; Ollie:",Stan); sort(Ollie.begin(),Ollie.end()); cnt=unique(Ollie.begin(),Ollie.end())-Ollie.begin(); for(int i=0;i<cnt;i++) printf(" %d",Ollie[i]); puts(";"); } return 0;}
- POJ 2464 Brownie Points II(树状数组||线段树)
- POJ 2464 Brownie Points II 树状数组||线段树
- POJ 2464 Brownie Points II --树状数组
- poj 2464 Brownie Points II 树状数组
- POJ 2464 Brownie Points II(树状数组+扫描线)
- POJ 2464 Brownie Points II(树状数组)
- Brownie Points II - POJ 2464 线段树
- Poj 3416 Crossing + Poj 2464 Brownie Points II (树状数组)
- 线段树专题:poj 2464 Brownie Points II
- POJ 2464 Brownie Points II(线段树:扫描线)
- poj 2464 Brownie Points II
- UVA 10869 - Brownie Points II(树状数组+离散化)
- poj2464 Brownie Points II 树状数组
- UVA 10869 - Brownie Points II(树状数组)
- uva 10869 - Brownie Points II(树状数组)
- poj 2464 Brownie Points II(两棵线段树——线段树区间和)
- POJ_2464 Brownie Points II 线段树
- UVA10869 - Brownie Points II(线段树)
- PCF8574 I/O扩展
- 3D游戏中的场景管理(八叉树和BSP树简介)
- matlab知识积累一
- 高效代码审查的十个经验
- A*算法寻路之Ogre实践
- POJ 2464 Brownie Points II(树状数组||线段树)
- OGRE框选制作
- Verilog HDL语言的四相八拍步进电机驱动
- eclipse svn插件报错
- 开源软件之七宗罪以及背后的阴谋
- C:\windows\system32\config\systemprofile\下创建的desktop 与服务有关
- swfobject.js
- 写在末日来临之前的2012 CSDN 博客之星评选
- linux下安装vmtools方法