SDOI2011 拦截导弹
题解:
对于第一问,我们求二维LIS即可;
对于第二问,我们可以记录向前最长长度,向前最长方案数,向后最长长度,向后最长方案数。
其实改改树状数组即可。
还有,方案数一定要开double。
代码:
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 50050
inline int rd()
{
int f=,c=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){c=*c+ch-'';ch=getchar();}
return f*c;
}
int n;
struct node
{
int h,v,s,f,g;
double w1,w2;
}p[N],tmp[N];
bool cmph(node a,node b)
{
return a.h>b.h;
}
bool cmpH(node a,node b)
{
return a.h<b.h;
}
bool cmps(node a,node b)
{
return a.s<b.s;
}
struct pR
{
int x,y;
}ph[N],pv[N];
struct Pair
{
int x;
double y;
Pair(){x=,y=0.0;}
Pair(int x,double y):x(x),y(y){}
};
bool cmp(pR a,pR b)
{
return a.x<b.x;
}
struct BIT
{
Pair v[N];
void up(int x,int d,double c)
{
while(x<N)
{
if(v[x].x<d)v[x]=Pair(d,c);
else if(v[x].x==d)v[x].y+=c;
x+=(x&-x);
}
}
void clear(int x)
{
while(x<N&&v[x].x)
{
v[x]=Pair(,0.0);
x+=(x&-x);
}
}
Pair down(int x)
{
Pair ret;
while(x)
{
if(v[x].x>ret.x)ret=v[x];
else if(v[x].x==ret.x)ret.y+=v[x].y;
x-=(x&-x);
}
return ret;
}
}tr;
int max_v;
void cdq(int l,int r)
{
if(l==r)return ;
int mid = (l+r)>>;
cdq(l,mid);
sort(p+l,p+mid+,cmph);
sort(p+mid+,p+r+,cmph);
int i,j;
for(i=mid+,j=l;i<=r;i++)
{
while(j<=mid&&p[i].h<=p[j].h)
{
tr.up(max_v-p[j].v,p[j].f,p[j].w1);
j++;
}
Pair tm = tr.down(max_v-p[i].v);
if(p[i].f<tm.x+)
{
p[i].f=tm.x+;
p[i].w1=tm.y;
}else if(p[i].f==tm.x+)p[i].w1+=tm.y;
}
for(j=j-;j>=l;j--)tr.clear(max_v-p[j].v);
sort(p+l,p+r+,cmps);
cdq(mid+,r);
}
void CDQ(int l,int r)
{
if(l==r)return ;
int mid = (l+r)>>;
CDQ(mid+,r);
sort(p+l,p+mid+,cmpH);
sort(p+mid+,p+r+,cmpH);
int i,j;
for(i=l,j=mid+;i<=mid;i++)
{
while(j<=r&&p[i].h>=p[j].h)
{
tr.up(p[j].v,p[j].g,p[j].w2);
j++;
}
Pair tm = tr.down(p[i].v);
if(p[i].g<tm.x+)
{
p[i].g=tm.x+;
p[i].w2=tm.y;
}else if(p[i].g==tm.x+)p[i].w2+=tm.y;
}
for(j=j-;j>mid;j--)tr.clear(p[j].v);
sort(p+l,p+r+,cmps);
CDQ(l,mid);
}
int ans;
int main()
{
n=rd();
for(int h,v,i=;i<=n;i++)
{
h=rd(),v=rd();
ph[i].x=h,ph[i].y=i;
pv[i].x=v,pv[i].y=i;
p[i].s=i;
}
sort(ph+,ph++n,cmp);
for(int las=-,k=,i=;i<=n;i++)
{
if(las!=ph[i].x)
{
las = ph[i].x;
k++;
}
p[ph[i].y].h=k;
}
sort(pv+,pv++n,cmp);
for(int las=-,k=,i=;i<=n;i++)
{
if(las!=pv[i].x)
{
las = pv[i].x;
k++;
max_v=k+;
}
p[pv[i].y].v=k;
}
for(int i=;i<=n;i++)p[i].f=,p[i].w1=1.0;
cdq(,n);
for(int i=;i<=n;i++)ans=max(ans,p[i].f);
printf("%d\n",ans);
for(int i=;i<=n;i++)p[i].g=,p[i].w2=1.0;
CDQ(,n);
double sum = ;
for(int i=;i<=n;i++)
{
if(p[i].f+p[i].g-==ans)
{
sum+=p[i].w1*p[i].w2;
}
}
sum/=(double)ans;
for(int i=;i<=n;i++)
{
if(p[i].f+p[i].g-==ans)
{
printf("%.5lf ",p[i].w1*p[i].w2/sum);
}else
{
printf("0.00000 ");
}
}
printf("\n");
return ;
}
SDOI2011 拦截导弹的更多相关文章
- bzoj 2244: [SDOI2011]拦截导弹 cdq分治
2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 237 Solved: ...
- 【BZOJ2244】[SDOI2011]拦截导弹(CDQ分治)
[BZOJ2244][SDOI2011]拦截导弹(CDQ分治) 题面 BZOJ 洛谷 题解 不难发现这就是一个三维偏序+\(LIS\)这样一个\(dp\). 那么第一问很好求,直接\(CDQ\)分治之 ...
- [BZOJ2244][SDOI2011]拦截导弹 CDQ分治
2244: [SDOI2011]拦截导弹 Time Limit: 30 Sec Memory Limit: 512 MB Special Judge Description 某国为了防御敌国的导弹 ...
- 【LG2481】[SDOI2011]拦截导弹
[LG2481][SDOI2011]拦截导弹 题面 洛谷 题解 可以看出第一问就是一个有关偏序的\(LIS\),很显然可以用\(CDQ\)优化 关键在于第二问 概率\(P_i=\) \(总LIS数\) ...
- P2487 [SDOI2011]拦截导弹
题目 P2487 [SDOI2011]拦截导弹 做\(SDOI\)有种想评黑的感觉,果然还是太弱了 做法 独立写(调)代码三个小时祭 简化题目:求二维最长不上升子序列及每个点出现在最长不上升子序列概率 ...
- BZOJ 2244: [SDOI2011]拦截导弹 DP+CDQ分治
2244: [SDOI2011]拦截导弹 Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截 ...
- BZOJ2244 [SDOI2011]拦截导弹 【cdq分治 + 树状数组】
题目 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截任意速度的导弹,但是以后每一发炮弹都不能高于前一发的高度,其 ...
- BZOJ2244: [SDOI2011]拦截导弹(CDQ分治,二维LIS,计数)
Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截任意速度的导弹,但是以后每一发炮弹都不能高 ...
- bzoj 2244 [SDOI2011]拦截导弹(DP+CDQ分治+BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2244 [题意] 给定n个二元组,求出最长不上升子序列和各颗导弹被拦截的概率. [思路] ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
随机推荐
- Codeforces - 814B - An express train to reveries - 构造
http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...
- python __builtins__ tuple类 (68)
68.'tuple', 转换为元组类型 class tuple(object) | tuple() -> empty tuple | tuple(iterable) -> tuple in ...
- python 类型转换总结
一.数字和字符串 >>> ord('a') # ascii码 97 >>> chr(97) 'a' >>> >>> hex(16 ...
- Linux下自动还原MySQL数据库的Shell脚本
创建shell脚本topjui_source.exp,内容如下: #!/usr/bin/expect spawn echo "###### running... ######" s ...
- curry柯里化函数实现
curry柯里化函数实现 参考文章: 一行写出javascript函数式编程中的curry 感谢作者分享 第一步: 缓存原始函数的参数个数 function curry(fn) { var limit ...
- Java项目的命名规则
Java类的命名规范如下: 1. 项目名全部小写 2. 包名全部小写 3. 类名首字母大写,如果类名由多个单词组成,每个单词的首字母都要大写. 如:public class MyFirstClass{ ...
- 18.3.2从Class上获取信息(内部类接口等)
内部类 接口.枚举.注释类型
- oracle 查看未关闭连接
查看连接状态.问题电脑等信息: select sid,serial#,username,program,machine,status from v$session; 2.查看sql; select ...
- python正则表达式多次提取数据(一个规则提取多组数据)
import re ttt='"FileName":"陈雪凝 - <em>绿色<\/em>","AlbumID":& ...
- 定时器、线程queue、进程池和线程池
1.定时器 指定n秒后,执行任务 from threading import Timer,current_thread import os def hello(): print("%s he ...