bzoj 2244
没有正确分析路径可能的条数,它是指数增长的,会爆long long。
然后就是正反两次时间分治。
另一个就是max with count,即带计数的最值,即除了记录最值,还要记录最值取得的次数。
/**************************************************************
Problem: 2244
User: idy002
Language: C++
Result: Accepted
Time:4108 ms
Memory:4520 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#define oo 0x3f3f3f3f
#define N 50010
using namespace std; typedef bool (*Cmp)( int a, int b ); struct Point {
int x, y;
Point(){}
Point( int x, int y ):x(x),y(y){}
};
struct Info {
int v;
long double c;
Info(){}
Info( int v, long double c ):v(v),c(c){}
void add( Info o ) {
if( o.v>v )
*this = o;
else if( o.v==v )
c += o.c;
}
}; int n;
Point pts[N];
Info dp[][N];
Info bit[N];
int q[N];
Cmp cmp;
int disc[N], dtot;
long double ans[N]; bool cmpa( int a, int b ) {
if( pts[a].x!=pts[b].x ) return pts[a].x<pts[b].x;
if( pts[a].y!=pts[b].y ) return pts[a].y<pts[b].y;
return a<b;
}
bool cmpb( int a, int b ) {
if( pts[a].x!=pts[b].x ) return pts[a].x>pts[b].x;
if( pts[a].y!=pts[b].y ) return pts[a].y>pts[b].y;
return a<b;
}
void modify( int pos, Info o ) {
if( cmp==cmpb ) pos = dtot+-pos;
for( int i=pos; i<=dtot; i+=i&-i )
bit[i].add(o);
}
void clear( int pos ) {
if( cmp==cmpb ) pos = dtot+-pos;
for( int i=pos; i<=dtot; i+=i&-i )
bit[i] = Info(-oo,);
}
Info query( int pos ) {
if( cmp==cmpb ) pos = dtot+-pos;
Info o(-oo,);
for( int i=pos; i; i-=i&-i )
o.add(bit[i]);
return o;
}
void cdq( Info dp[], int lf, int rg ) {
if( lf==rg ) {
dp[lf].add( Info(,) );
return;
}
int mid=(lf+rg)>>;
cdq( dp, lf, mid );
for( int i=lf; i<=rg; i++ )
q[i] = i;
sort( q+lf, q+rg+, cmp );
for( int t=lf; t<=rg; t++ ) {
int i=q[t];
if( i<=mid ) {
modify( pts[i].y, dp[i] );
} else {
Info o = query(pts[i].y);
o.v++;
dp[i].add( o );
}
}
for( int t=lf; t<=rg; t++ ) {
int i=q[t];
if( i<=mid )
clear( pts[i].y );
}
cdq( dp, mid+, rg );
}
int main() {
scanf( "%d", &n );
for( int i=,x,y; i<=n; i++ ) {
scanf( "%d%d", &x, &y );
pts[i] = Point(x,y);
disc[++dtot] = y;
}
reverse( pts+, pts++n );
sort( disc+, disc++dtot );
dtot = unique( disc+, disc++dtot ) - disc - ;
for( int i=; i<=n; i++ )
pts[i].y = lower_bound( disc+, disc++dtot, pts[i].y ) - disc; cmp = cmpa;
cdq( dp[], , n );
cmp = cmpb;
reverse( pts+, pts++n );
cdq( dp[], , n );
reverse( dp[]+, dp[]++n ); Info info(-oo,);
for( int i=; i<=n; i++ )
info.add( dp[][i] );
printf( "%d\n", info.v );
for( int i=; i<=n; i++ ) {
if( dp[][i].v+dp[][i].v- == info.v ) {
ans[i] = dp[][i].c*dp[][i].c/info.c;
} else
ans[i] = 0.0;
}
reverse( ans+, ans++n );
for( int i=; i<=n; i++ )
printf( "%.5Lf\n", ans[i] );
}
bzoj 2244的更多相关文章
- bzoj 2244 [SDOI2011]拦截导弹(DP+CDQ分治+BIT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2244 [题意] 给定n个二元组,求出最长不上升子序列和各颗导弹被拦截的概率. [思路] ...
- 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]拦截导弹
#include<cstdio> #include<iostream> #include<algorithm> #define M 100009 using nam ...
- BZOJ 2244: [SDOI2011]拦截导弹 [CDQ分治 树状数组]
传送门 题意:三维最长不上升子序列以及每个元素出现在最长不上升子序列的概率 $1A$了好开心 首先需要从左右各求一遍,长度就是$F[0][i]+F[1][i]-1$,次数就是$G[0][i]*G[1] ...
- bzoj 2244 [SDOI2011]拦截导弹(dp+CDQ+树状数组)
传送门 题解 看了半天完全没发现这东西和CDQ有什么关系…… 先把原序列翻转,求起来方便 然后把每一个位置表示成$(a,b,c)$其中$a$表示位置,$b$表示高度,$c$表示速度,求有多少个位置$a ...
- BZOJ - 2244 拦截导弹 (dp,CDQ分治+树状数组优化)
题目链接 dp进阶之CDQ分治优化dp. 前置技能:dp基本功底,CDQ分治,树状数组. 问题等价于求二维最长上升子序列,是一个三维偏序问题(时间也算一维). 设$dp[i]=(l,x)$为以第i枚导 ...
- BZOJ 2244 [SDOI2011]拦截导弹 ——CDQ分治
三维偏序,直接CDQ硬上. 正反两次CDQ统计结尾的方案数,最后统计即可. #include <cstdio> #include <cstring> #include < ...
- BZOJ 2244 [SDOI2011]拦截导弹 (三维偏序CDQ+线段树)
题目大意: 洛谷传送门 不愧为SDOI的duliu题 第一问?二元组的最长不上升子序列长度?裸的三维偏序问题,直接上$CDQ$ 由于是不上升,需要查询某一范围的最大值,并不是前缀最大值,建议用线段树实 ...
随机推荐
- oracle关键字作为字段名使用方法
有时我们在定义字段名及别名时所用名与oracle关键字同名,这时该如何处理呢? 其实很简单,只要在此关键字加上"",如"group" SQL> DROP ...
- 修复TortoiseGit文件夹和文件图标不显示问题的多种解决办法以及重启之后TortoiseGit图标注册表又不见了的解决办法
一 首先进行第一种尝试 打开 regedit.exe ,准备修改注册表 找到 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ ...
- if(a==1) & if(1==a) 区别
[前提] 在公司参加项目时,看到前辈写if比较数值是否相等,经常会写 if(1==a) ,觉得有些奇怪,如是乎,将调查结果写下来记录一下. [结果] if(a==1) 与 if(1==a)是没有什么区 ...
- plsql developer配置
一:今天plsql developer连接 出问题了 ,Oracleclient没正确安装 0.连接vpn 1.环境变量:TNS_ADMIN = D:\worksoftware\oracleClien ...
- 多线程 or I/O复用select/epoll
1:多线程模型适用于处理短连接,且连接的打开关闭非常频繁的情形,但不适合处理长连接.线程模型默认情况下,在Linux下每个线程会开8M的栈空间,在TCP长连接的情况下,以2000/分钟的请求为例,几乎 ...
- 入门ROS教程与视频汇总(kinetic)
参考网址: Richard Wang 3 Shawn Chen 部分视频网址: http://v.youku.com/v_show/id_XMjUxMTc5MzE5Mg http://i.you ...
- 触发器中的inserted表和deleted表
触发器语句中使用了两种特殊的表:deleted 表和 inserted 表.Microsoft? SQL Server 2000 自动创建和管理这些表.可以使用这两个临时的驻留内存的表测试某些数据修改 ...
- 基于 Struts2 的文件下载
介于上篇我们讲述了基于 Struts2 的单文件和多文件上传,这篇我们来聊一聊基于 Struts2 的文件下载. 1.导 jar 包 commons-io-2.0.1.jar struts2-core ...
- 8-1 Stacks of Flapjacks UVA120
题意: 有一叠煎饼在锅里 n n<=30张 每张都有一个数字 代表它的大小 厨师每次可以选择一个数k 把从锅底开始数第k张上面的煎饼全部反过来 即原来的在上面的煎饼现在到了下面 ...
- ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. 通过pip安装 num ...