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$ 由于是不上升,需要查询某一范围的最大值,并不是前缀最大值,建议用线段树实 ...
随机推荐
- raw数据类型
Oracle中用于保存位串的数据类型是RAW,LONG RAW(推荐使用BLOB). RAW,类似于CHAR,声明方式RAW(L),L为长度,以字节为单位,作为数据库列最大2000,作为变量最大327 ...
- 一个简单的java jdbc案例
有些时候,配置一个spring+mybatis框架,然后写xml,dao ,service显得特别繁琐. 如果我们只是想查一下数据库,不考虑连接复用也不考虑动态sql,可以用原生的jdbc来实现,方便 ...
- layui table表格字段过长,展示不完整时,鼠标放到上面展示完整信息
亲测可以直接用 1.首先每个列都有一个title,里面放入完整信息,然后写一个如下的function, function tdTitle(){ $('th').each(function(index, ...
- crond检查服务状态
代码如下: * */1 * * * /etc/init.d/ntpd status;if [ $? -ne 0 ];then /etc/init.d/ntpd start; fi
- 你的组织使用了 windows defender 应用程序控制来阻止此应用
=============================================== 2018/2/8_第1次修改 ccb_warlock === ...
- JAVA中分为基本数据类型和引用数据类型区别
一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit),即1个字节,取值范围-128~127,默认值0 short:短整型,在内存中占16位,即2个字节,取值范围-32768 ...
- git —— 基本命令以及操作(No.1)
git基本命令(附加描述) 1.把文件添加到暂存区$ git add readme.txt 2.把暂存区的文件文件添加到仓库$ git commit -m "提交说明" 备注:ad ...
- Graham求凸包模板
struct P { double x, y; P(, ):x(x), y(y) {} double add(double a, double b){ ; return a+b; } P operat ...
- Java---容器基础总结
Java提供了大量持有对象的方式: (1) 数组将数字与对象联系起来. 它保存类型明确的对象,查询对象时,不需要对结果做类型转换.它可以是多维的, 可以保存基本类型的数据. 但是,数组一旦生成,其容量 ...
- RobotCraft 2017 第二届国际机器人学暑期学校 2nd Edition of International Robotics Summer School
原文网址:http://www.ros.org/news/2017/02/2nd-edition-of-international-robotics-summer-school-robotcraft- ...