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 ...
随机推荐
- 洛谷 P2347 砝码称重 & [NOIP1996提高组](dp,枚举)
传送门 解题思路 一看数据范围<1000就坚定了我暴力的决心(不愧是1996年代的题还是t4QAQ) 所以很显然,暴力之中有一点dp的思想,就是把它们像多重背包一样拆分,拆成a1+a2+a3+a ...
- homestead修改php版本
登录后 如果之前没有设置过root密码 sudo passwd root 以root 权限执行如下命令,选择对应php版本 # 查看所有 php 版本和当前版本 update-alternatives ...
- Datatable 中的数据查询(查询不重复记录)
http://blog.csdn.net/lovexiaoxiao/article/details/3734932 //在sql中我们使用distinct查询不重复记录 //然而我在项目中表关系 ...
- MacOS X快捷键一览(http://www.cnblogs.com/ios8/p/Mac-OSX-keyword-cmd.html)
ctrl+shift 快速放大dock的图标会暂时放大,而如果你开启了dock放大Command+Option+W ...
- VB Open 函数详解 打开、关闭、读、写文件
(一)打开和关闭文件 1.顺序文件 打开顺序文件,我们可以使用Open语句.它的格式如下:Open pathname For [Input |Output |Append] As [ ...
- 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)
链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- 牛客练习赛14 A n的约数 (数论)
链接:https://ac.nowcoder.com/acm/contest/82/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288 ...
- Hadoop之MapReduce 本机windows模式运行
hadoop在windows本机运行 (1)在 windows环境下编译好的hadoop放到没有中文和空格的路径下 (2)编译好的hadoop内的hadoop.all文件要放到windows机器的wi ...
- Azure IoT 技术研究系列2
上篇博文中,我们主要介绍了Azure IoT Hub的基本概念.架构.特性: Azure IoT 技术研究系列1-入门篇 本文中,我们继续深入研究,做一个起步示例程序:模拟设备注册到Azure IoT ...
- compile and link C/CPP programs on Mac
ref: https://stackoverflow.com/questions/29987716/cannot-use-gsl-library-on-macos-ld-symbols-not-fou ...