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 ...
随机推荐
- Python IPy模块
#!/usr/bin/env python # -*- coding: utf-8 -* # Created by YangYongming at 2018/09/17 20:22 # FileNam ...
- 采集化工内容写入TXT文本
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- GoLang基础数据类型--->数组(array)详解
GoLang基础数据类型--->数组(array)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Golang数组简介 数组是Go语言编程中最常用的数据结构之一.顾名 ...
- 函数和常用模块【day04】:内置函数(八)
一.常用内置函数 1.表格 二.内置函数详情(1-10) 1.abs(x) 功能:取数的绝对值 1 2 >>> abs(-1) #取-1的绝对值 1 2.all(iterable) ...
- 添加dubbo.xsd的方法
整合dubbo-spring的时候,配置文件会报错 因为 阿里关闭在线的域名了.需要本地下载xsd文件 所以,需要下载本地引入. 解决方式: 在dubbo的开源项目上找到xsd文件: htt ...
- 怎么简单高效破解MyEclipse10、获取注册码
亲测有效 附上地址:https://www.cnblogs.com/caohuimingfa/p/6659902.html
- vue确认密码
rules: { pwd:[{ required:true, message:'创建密码',trigger:'blur' }], cpwd:[{ required:true,message:'确认密码 ...
- ThinkPHP 3.2 用户注册邮箱验证帐号找回密码
一.前言 当然现在有的网站也有手机短信的方式找回密码,原理就是通过发送验证码来验明正身,和发送邮件验证一样,最终还是要通过重置密码来完成找回密码的流程. 本文将使用PHP+Mysql+jQuery来实 ...
- Spring 学习03
一.上节内容回顾 1 注解ioc操作 (1)使用注解创建对象 - 四个注解 (2)使用注解注入属性 - 两个注解 2 aop (1)aop原理 (2)aop术语 - 切入点 - 增强 - 切面 3 s ...
- iOS safari 苹果手机如何阻止页面弹性“橡皮筋效果”?
苹果上这个上下弹的效果对于有固定导航的页面,体验很不好 知乎上搜到一个并不是完美方案:https://www.zhihu.com/question/22256539 完美方案是有个国外插件叫:prev ...