codeforce 139E
成段更新+离散化才能过,数据好强。。
单点更新挂在了test27,下次做到成段更新再来做!
/*
期望=存活概率*点权值/100
ans=sum(期望)
离散化树木权值,数轴统计累加可能倒下的树木概率(直接加权值即可)
线段树单点,sum[rt]维护在这个区间中所有蘑菇的存活期望值
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 100005
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
using namespace std;
struct Tree{
int pos,h,pl,pr;//坐标,高度,左概率,右概率
}tree[maxn];
struct Mushroom{
int pos,w;//蘑菇坐标,蘑菇权值
}mushroom[maxn];
int axis[maxn<<],cnt,tot;
double poss[maxn<<];//排序后的坐标点,数轴[1,maxn<<3]上存活概率
double sum[maxn<<];
void build(int l,int r,int rt){
sum[rt]=;
if(l==r)
return;
int m=l+r>>;
build(lson);
build(rson);
}
inline pushup(int rt){
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void update(int pos,double val,int l,int r,int rt){
sum[rt]+=val;
if(l==r) return;
int m=l+r>>;
if(pos<=m) update(pos,val,lson);
else update(pos,val,rson);
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
cnt=;
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&tree[i].pos,&tree[i].h,&tree[i].pl,&tree[i].pr);
axis[cnt++]=tree[i].pos;
axis[cnt++]=tree[i].pos-tree[i].h;
axis[cnt++]=tree[i].pos+tree[i].h;
}
for(int i=;i<=m;i++){
scanf("%d%d",&mushroom[i].pos,&mushroom[i].w);
axis[cnt++]=mushroom[i].pos;
} sort(axis,axis+cnt);
int tot=unique(axis,axis+cnt)-axis;//离散化
for(int i=;i<=tot;i++)//一开始所有的坐标上存活概率都是1
poss[i]=;
//每个点找坐标logn,打标记最多n,复杂度O(n*n)
for(int i=;i<=n;i++){
int pos=lower_bound(axis,axis+tot,tree[i].pos)-axis+;
int posl=lower_bound(axis,axis+tot,tree[i].pos-tree[i].h)-axis+;
int posr=lower_bound(axis,axis+tot,tree[i].pos+tree[i].h)-axis+;
for(int j=posl;j<pos;j++)//倒在左区间的概率
poss[j]*=-(double)tree[i].pl/;
for(int j=pos+;j<=posr;j++)//倒在右区间的概率
poss[j]*=-(double)tree[i].pr/;
}
//至此统计完概率,开始建立线段树
build(,tot,);
for(int i=;i<=m;i++){
int pos=lower_bound(axis,axis+tot,mushroom[i].pos)-axis+;
update(pos,mushroom[i].w*poss[pos],,tot,);//把权值*期望更新到线段树中
}
printf("%.4lf\n",sum[]); return ;
}
codeforce 139E的更多相关文章
- Codeforce - Street Lamps
Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...
- Codeforce Round #216 Div2
e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...
- Codeforce 水题报告(2)
又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...
- codeforce 375_2_b_c
codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...
- codeforce 367dev2_c dp
codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...
- 三维dp&codeforce 369_2_C
三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...
- 强连通分量&hdu_1269&Codeforce 369D
强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...
- 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D
[树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
随机推荐
- nGrinder TestRunnerInsertMysqlMore.groovy
s C:\Users\Lindows\workspace\GroovyTest\src\com\iteye\lindows\mysql\TestRunnerInsertMysqlMore.groovy ...
- Premiere导入视频之后音频轨没有内容
我用手机录的视频,在导入premiere新建序列之后呢并没有声音啊,音频轨没有内容.去贴吧里面问啊什么的都不靠谱,热心回答的人也不多.想学到东西,在这个年代如果你不愿意掏钱的话就只能靠一个办法:搜索. ...
- JavaSE学习总结(九)—— Java访问数据库(JDBC)
一.JDBC简介 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java ...
- Linux重启服务器步骤
- Phalcon的Mvc结构及启动流程(部分源码分析)
Phalcon本身有支持创建多种形式的Web应用项目以应对不同场景,包括迷你应用.单模块标准应用.以及较复杂的多模块应用 创建项目 Phalcon环境配置安装后,可以通过命令行生成一个标准的Phalc ...
- Extmail 批量添加邮箱用户
Extmail 设置批量添加邮箱用户 需要修改 userctl.pl 文件 修改 userctl.pl 文件 cd /var/www/extsuite/extman/tools 编辑 userc ...
- luogu P2113 看球泡妹子
2333 这么水的蓝题 f[i][j] 表示看了i场比赛,小♀红的什么东西为j时小♂明的什么值 强行压维蛤蛤 剩下的转移很简单(注意i的循环顺序从后往前,01背包) (具体见代码) #include& ...
- mysql 原理 ~ checkpoint
一 简介:今天咱们来聊聊checkpoint 二 定义: checkpoin是重做日志对数据页刷新到磁盘的操作做的检查点,通过LSN号保存记录,作用是当发生宕机等crash情况时,再次启动时会查询ch ...
- 启动apache 提示Starting httpd: AH00558
Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain nam ...
- weblogic对JSP预编译、weblogic读取JSP编译后的class文件、ant中weblogic.jspc预编译JSP
我们都知道在weblogic中JSP是每次第一次访问的时候才会编译,这就造成第一次访问某个JSP的时候性能下降,有时候我们也希望JSP被编译成class然后打包在jar中实现隐藏JSP的功能,下面介绍 ...