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 ...
随机推荐
- git 线上回滚问题纪要
1. git revert 作用 revert 用来取消置顶的提交的内容 2. 前提说明 当讨论 revert 时,需要分两种情况,因为 commit 分为两种: 一种是常规的 commit,也就是使 ...
- iptables 代理转发配置
增加命令 [root@pre /]# iptables -t nat -A PREROUTING -s 39.15.15.15/32 -d 221.11.8.200/32 -p tcp -m tcp ...
- javascript 利用冒泡机制显示与隐藏模态框
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- javascript 模拟日历
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java基础中的一些概念理解
同步 和 异步区别 同步和异步通常用来形容一次方法的调用. 同步方法调用一旦开始,调用者必须等到方法调用返回后,才能继续后续的行为.而异步方法调用更像一个消息传递,一旦开始,方法调用就会立即返回,调用 ...
- mysql 语句 GROUP_CONCAT
select * from blog_log;+----+---------------------+-------+--------+| id | time | level | info |+--- ...
- windws 下 sublime Text 3 ·安装的安装与激活
下载sublime 我们可以到官网进行下载对应的版本 https://www.sublimetext.com/3 如下是官网的内容(我选择的是Windows 64 bit). Sublime Text ...
- JavaScript学习 - 基础(八) - DOM 节点 添加/删除/修改/属性值操作
html代码: <!--添加/删除/修改 --> <div id="a1"> <button id="a2" onclick=&q ...
- JavaScript学习 - 基础(一)
ECMAscript ECMAscript是一个重要的标准,但它并不是JAVAscript唯一的部分,当然,也不是唯一标准化的部分,实际上,一个完整的JAVAscript实现是由一下3个不同的部分组成 ...
- python - str和repr方法:
# python 内置__str__()和__repr__()方法: #显示自定制 # 示例1 # a = 123 # print(a.__str__()) # 示例2 class Test(): d ...