codeforces 668C - Little Artem and Random Variable
题目链接:http://codeforces.com/contest/668/problem/C
-------------------------------------------------------------------------------------------
大概看一下发现题目给了一些条件限制 然后要解一个方程组
不过数据范围很大 如果直接去解的话显然很困难
考虑到此题是建立在概率的模型上的 因此我们可以用前缀和的方式先把输入处理一下
然后就转化为以下子问题
$0 <= x_1, y_1, x_2, y_2 <= 1$
$x_1 * y_1 = a$
$x_2 * y_2 = b$
$x_1 + x_2 = 1$
$y_1 + y_2 = 1$
给定$a\ b$求解$x_1\ x_2\ y_1\ y_2$
在草稿纸上画画我们可以发现此处是可以三分的
不过继续观察下我们可以限定所有的$y_i <= x_i$
于是就可以写更为简单的二分了
并且在这个限定条件下 每次求出的解实际上是相互独立的
因此对于每一对解 我们都可以通过二分处理
这样这题就以$O(nlog(10^6))$愉快地解决了
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + ;
double p1[N], p2[N];
double ans1[N], ans2[N];
int n;
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i)
scanf("%lf", &p1[i]);
for(int i = ; i <= n; ++i)
p1[i] += p1[i - ];
for(int i = ; i <= n; ++i)
scanf("%lf", &p2[i]);
for(int i = n - ; i; --i)
p2[i] += p2[i + ];
for(int i = ; i < n; ++i)
{
double L, R, mid;
int t = ;
L = max(sqrt(p1[i]), ans1[i - ]);
R = ;
while(++t <= )
{
mid = (L + R) / ;
if(( - mid) * ( - p1[i] / mid) <= p2[i + ])
R = mid;
else
L = mid;
}
ans1[i] = R;
ans2[i] = p1[i] / R;
}
ans1[n] = ans2[n] = ;
for(int i = n; i > ; --i)
{
ans1[i] -= ans1[i - ];
ans2[i] -= ans2[i - ];
}
for(int i = ; i <= n; ++i)
printf("%.8f%c", ans1[i], i != n ? ' ' : '\n');
for(int i = ; i <= n; ++i)
printf("%.8f%c", ans2[i], i != n ? ' ' : '\n');
return ;
}
codeforces 668C - Little Artem and Random Variable的更多相关文章
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学
C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...
- Introduction to Probability (5) Continus random variable
CONTINUOUS RANDOM VARIABLES AND PDFS 连续的随机变量,顾名思义.就是随机变量的取值范围是连续的值,比如汽车的速度.气温.假设我们要利用这些參数来建模.那么就须要引 ...
- Jmeter入门16 数据构造之随机数Random Variable & __Random函数
接口测试有时参数使用随机数构造.jmeter添加随机数两种方式 1 添加配置 > Random Variable 2 __Random函数 ${__Random(1000,9999) ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...
- 【概率论】4-1:随机变量的期望(The Expectation of a Random Variable Part II)
title: [概率论]4-1:随机变量的期望(The Expectation of a Random Variable Part II) categories: - Mathematic - Pro ...
- 【概率论】3-8:随机变量函数(Functions of a Random Variable)
title: [概率论]3-8:随机变量函数(Functions of a Random Variable) categories: Mathematic Probability keywords: ...
- 【概率论】4-1:随机变量的期望(The Expectation of a Random Variable Part I)
title: [概率论]4-1:随机变量的期望(The Expectation of a Random Variable Part I) categories: - Mathematic - Prob ...
- codeforces 442C C. Artem and Array(贪心)
题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CodeForces - 669D Little Artem and Dance 想法题 多余操作
http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...
随机推荐
- Luogu p2456 二进制方程
这是一道我也不知道我gu了多久的题目 (然鹅还有n多任务没有完成) 反正--我太难了 好了言归正传,题目链接 是一道校内测的题目(现在应该没有人没考了吧?) 思路的话,是神仙并查集√ 觉得虽然并查集很 ...
- kafka连接器
独立模式 bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.prope ...
- MySQL explain,Extra分析(转)
explain结果中有一个Extra字段,对分析与优化SQL有很大的帮助 数据准备: create table user ( id int primary key, name varchar(20), ...
- SQL执行计划之sql_trace
一,sql_trace的作用:用以描述SQL的执行过程的trace输出. - SQL是如何操作数据的 - SQL执行过程中产生了哪些等待事件 - SQL执行中消耗了多少资 ...
- WPF拖拽文件(拖入拖出),监控拖拽到哪个位置,类似百度网盘拖拽
1.往wpf中拖文件 // xaml <Grid x:Name="grid_11" DragOver="Grid_11_DragOver" Drop=&q ...
- Scala学习笔记(6)对象
1.单例对象.Scala没有静态方法或字段,可以使用object这个语法结构来达到同样的目的.对象定义了单个实例,包含了你想要的特性. object Accounts{ def newUniqueNu ...
- vuex实现数据共享
1.store.js结构 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Sto ...
- jQuery进阶第三天(2019 10.12)
一.原生JS快捷的尺寸(属性)(注意这些属性的结果 不带PX单位) clientWidth/clientHeight =====> 获得元素content+padding的宽/高: offse ...
- 为啥要使用Hessian
1.为啥要使用Hessian? 有需求就有市场,挨踢界也是一样,想要实现远程调用,Hessian就应运而生. 场景:有一个后台系统,基本上所有的用户管理都在这个系统里操作,其中有一个方法是添加用户的方 ...
- Codeforces Round #426 (Div. 2) - D
题目链接:http://codeforces.com/contest/834/problem/D 题意:给定一个长度为n的序列和一个k,现在让你把这个序列分成刚好k段,并且k段的贡献之和最大.对于每一 ...