bzoj 2244: [SDOI2011]拦截导弹
- #include<cstdio>
- #include<iostream>
- #include<algorithm>
- #define M 100009
- using namespace std;
- struct data
- {
- int x,y,z,f[];
- double sum[];
- }a[M],b[M];
- struct ss
- {
- int w;
- double su;
- }shu[M];
- int n,yy[M],zz[M],yl,zl,ans,tot,sta[M];
- double sum1;
- bool cmp(data a1,data a2)
- {
- if(a1.y==a2.y)
- return a1.x<a2.x;
- return a1.y<a2.y;
- }
- bool cmp1(data a1,data a2)
- {
- return a1.x>a2.x;
- }
- void updata(int i,int p)
- {
- int a1=a[i].z;
- for(;a1<=zl;a1+=a1&-a1)
- if(shu[a1].w<a[i].f[p])
- {
- if(shu[a1].w==)
- sta[++tot]=a1;
- shu[a1].w=a[i].f[p];
- shu[a1].su=a[i].sum[p];
- }
- else if(shu[a1].w==a[i].f[p])
- shu[a1].su+=a[i].sum[p];
- return;
- }
- void ask(int i,int p)
- {
- int a1=a[i].z;
- for(;a1;a1-=a1&-a1)
- if(a[i].f[p]<=shu[a1].w&&shu[a1].w)
- {
- a[i].f[p]=shu[a1].w+;
- a[i].sum[p]=shu[a1].su;
- }
- else if(a[i].f[p]==shu[a1].w+)
- a[i].sum[p]+=shu[a1].su;
- return;
- }
- void solve(int l,int r,int p)
- {
- if(l==r)
- {
- if(a[l].f[p]==)
- a[l].f[p]=a[l].sum[p]=;
- return;
- }
- int mid=(l+r)>>;
- int l1=l,l2=mid+;
- for(int i=l;i<=r;i++)
- if(a[i].x<=mid)
- b[l1++]=a[i];
- else
- b[l2++]=a[i];
- for(int i=l;i<=r;i++)
- a[i]=b[i];
- solve(l,mid,p);
- sort(a+l,a+mid+,cmp);
- int st=l;
- for(int i=mid+;i<=r;i++)
- {
- for(;a[st].y<=a[i].y&&st<=mid;st++)
- updata(st,p);
- ask(i,p);
- }
- for(int i=;i<=tot;i++)
- shu[sta[i]].w=shu[sta[i]].su=;
- tot=;
- solve(mid+,r,p);
- }
- int main()
- {
- scanf("%d",&n);
- for(int i=;i<=n;i++)
- {
- a[i].x=i;
- scanf("%d%d",&a[i].y,&a[i].z);
- yy[i]=a[i].y;
- zz[i]=a[i].z;
- }
- sort(yy+,yy+n+);
- sort(zz+,zz+n+);
- yl=unique(yy+,yy+n+)-yy-;
- zl=unique(zz+,zz+n+)-zz-;
- for(int i=;i<=n;i++)
- {
- a[i].y=yl-(lower_bound(yy+,yy+yl+,a[i].y)-yy)+;
- a[i].z=zl-(lower_bound(zz+,zz+zl+,a[i].z)-zz)+;
- }
- sort(a+,a+n+,cmp);
- solve(,n,);
- for(int i=;i<=n;i++)
- {
- a[i].x=n-a[i].x+;
- a[i].y=yl-a[i].y+;
- a[i].z=zl-a[i].z+;
- }
- sort(a+,a+n+,cmp);
- solve(,n,);
- sort(a+,a+n+,cmp1);
- for(int i=;i<=n;i++)
- if(a[i].f[]>ans)
- {
- ans=a[i].f[];
- sum1=a[i].sum[];
- }
- else if(a[i].f[]==ans)
- sum1+=a[i].sum[];
- printf("%d\n",ans);
- for(int i=;i<=n;i++)
- if(a[i].f[]+a[i].f[]-==ans)
- printf("%.5lf ",a[i].sum[]*a[i].sum[]/sum1);
- else
- printf("0.00000 ");
- return ;
- }
首先第一问明显是一个三维偏序集,速度,高度,时间,用CDQ分治做,然后我们把它反过来,在做一边CDQ分治,这两遍求出来的方案数组相乘,就是过这个点的方案数。
bzoj 2244: [SDOI2011]拦截导弹的更多相关文章
- bzoj 2244: [SDOI2011]拦截导弹 cdq分治
2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 237 Solved: ...
- BZOJ 2244: [SDOI2011]拦截导弹 DP+CDQ分治
2244: [SDOI2011]拦截导弹 Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截 ...
- bzoj 2244 [SDOI2011]拦截导弹(DP+CDQ分治+BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2244 [题意] 给定n个二元组,求出最长不上升子序列和各颗导弹被拦截的概率. [思路] ...
- bzoj 2244 [SDOI2011]拦截导弹(dp+CDQ+树状数组)
传送门 题解 看了半天完全没发现这东西和CDQ有什么关系…… 先把原序列翻转,求起来方便 然后把每一个位置表示成$(a,b,c)$其中$a$表示位置,$b$表示高度,$c$表示速度,求有多少个位置$a ...
- BZOJ 2244: [SDOI2011]拦截导弹 [CDQ分治 树状数组]
传送门 题意:三维最长不上升子序列以及每个元素出现在最长不上升子序列的概率 $1A$了好开心 首先需要从左右各求一遍,长度就是$F[0][i]+F[1][i]-1$,次数就是$G[0][i]*G[1] ...
- BZOJ 2244 [SDOI2011]拦截导弹 ——CDQ分治
三维偏序,直接CDQ硬上. 正反两次CDQ统计结尾的方案数,最后统计即可. #include <cstdio> #include <cstring> #include < ...
- BZOJ 2244 [SDOI2011]拦截导弹 (三维偏序CDQ+线段树)
题目大意: 洛谷传送门 不愧为SDOI的duliu题 第一问?二元组的最长不上升子序列长度?裸的三维偏序问题,直接上$CDQ$ 由于是不上升,需要查询某一范围的最大值,并不是前缀最大值,建议用线段树实 ...
- BZOJ 2244: [SDOI2011]拦截导弹 (CDQ分治 三维偏序 DP)
题意 略- 分析 就是求最长不上升子序列,坐标取一下反就是求最长不下降子序列,比较大小是二维(h,v)(h,v)(h,v)的比较.我们不看概率,先看第一问怎么求最长不降子序列.设f[i]f[i]f[i ...
- BZOJ:2244: [SDOI2011]拦截导弹
问题: printf("%.5f ",0):为什么错了? 注意: 初始值很重要 题解: 三维偏序问题: 记录从前往后最长上升子序列长度pref,条数preg 从后往前suff,su ...
随机推荐
- go框架
beego 的 http server… Author 逆雪寒 2015.12.02 原文地址 https://github.com/nixuehan/beego_you_know/blob/mast ...
- Kafka 快速起步(作者:杜亦舒)
Kafka 快速起步 原创 2017-01-05 杜亦舒 性能与架构 主要内容:1. kafka 安装.启动2. 消息的 生产.消费3. 配置启动集群4. 集群下的容错测试5. 从文件中导入数据,并导 ...
- JPA基础
目录 目录 1 一.JPA基础 2 1.1 JPA基础 2 1.2JPA开发过程 3 1.3 实体的生命周期及实体管理器常用方法 4 二.环境搭建 5 2.1 添加JPA支持 6 2.2 添加配置文件 ...
- ie6 span 换行IE6中float:right换行问题的替代解决方案
在IE6,IE7下使用<span>标签时,在加入右浮动样式后,会换行的bug解决方案: bug案例:新闻列表中,为使时间右对齐,加右浮动产生换行 <ul> <li> ...
- easyui combobox 智能提示搜索
<!-- 获取机会点名称列表 --><script> function initOpportunityNameFuzzyQuery() { $('#jihuidianmingc ...
- RESEACH PAPER
个,proquest的username和password赫然在目,别急,再看第4个结 果"HB Thompson Subscription Online Databases", ...
- 20145218 《Java程序设计》第四周学习总结
20145218 <Java程序设计>第四周学习总结 教材学习内容总结 继承 继承共同行为 继承基本上就是避免多个类间重复定义共同行为. 继承的三个好处:减少代码冗余:维护变得简单:扩展变 ...
- hdu----(4545)魔法串(LCS)
魔法串 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...
- 121. 122. 123. 188. Best Time to Buy and Sell Stock *HARD* 309. Best Time to Buy and Sell Stock with Cooldown -- 买卖股票
121. Say you have an array for which the ith element is the price of a given stock on day i. If you ...
- 2016年31款轻量高效的开源JavaScript插件和库
目前有很多网站设计师和开发者喜欢使用由JavaScript开发的插件和库,但同时面临一个苦恼的问题:它们中的大多数实在是太累赘而且常常降低网站的性能.其实,其中也有不少轻量级的插件和库,它们不仅轻巧有 ...