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$ 由于是不上升,需要查询某一范围的最大值,并不是前缀最大值,建议用线段树实 ...
随机推荐
- linux 获取时间后--自定义时间格式
自定义时间格式 =================================-===================================== #include <stdio.h ...
- ARC073E Ball Coloring
Problem AtCoder Solution 把点映射至二维平面,问题就变成了给定 \(n\) 个点,可以把点对 \(y=x\) 对称,求覆盖所有点的最小矩形面积. 可以先把所有点放到 \(y=x ...
- 公司xenserver搭建的使用
[root@xenserver ~]# ls -l /dev/disk/by-path/total 0lrwxrwxrwx 1 root root 9 Jan 19 16:33 pci-0000:0 ...
- centos7.2系统没有eth0网卡
最近一直在学centos7.5系统,偶然看到虚拟机里有7.2系统所以想练习一下(其实7.2和7.5差不多),但是打开虚拟机之后,发现没有eth0网卡 那没有eth0网卡就无法远程连接ssh,既然遇到了 ...
- No.7 selenium学习之路之Alert弹窗
Alert弹窗 弹窗是用工具选不到的~ 切换到alert driver.switch_to_alert() 新的语法:driver.switch_to.alert 注:新的语法不需要后面加括号 打印a ...
- 洛谷P2822组合数问题
传送门啦 15分暴力,但看题解说暴力分有30分. 就是找到公式,然后套公式.. #include <iostream> #include <cstdio> #include & ...
- 用戶登陸。防SQL注入,驗證碼不區分大小寫。。
if (string.Compare(TBCheckCode.Text, Session["CheckCodeI"].ToString(), true) == 0) ...
- SQL Server中常用全局变量介绍
在SQL Server中,全局变量是一种特殊类型的变量,服务器将维护这些变量的值.全局变量以@@前缀开头,不必进行声明,它们属于系统定义的函数.下表就是SQL Server中一些常用的全局变量. 全局 ...
- SonarQube的安装、配置与使用(windows)
onarQube是管理代码质量一个开放平台,可以快速的定位代码中潜在的或者明显的错误,下面将会介绍一下这个工具的安装.配置以及使用. 准备工作: 1.jdk(不再介绍) 2.sonarqube:htt ...
- JavaWeb--中文乱码小结
JavaWeb--中文乱码小结 出处:http://chriszz.sinaapp.com0.纯粹html乱码: 换个editor吧(有时候notepad都比sublime_text好用),最好是在& ...