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 ...
随机推荐
- 各类最新Asp .Net Core 项目和示例源码
1.网站地址:http://www.freeboygirl.com2.网站Asp .Net Core 资料http://www.freeboygirl.com/blog/tag/asp%20net%2 ...
- CF和OF的区别
进位标志CF和溢出标志OF的区别: 有符号数和无符号数只是认为的进行区分,计算机从来不区分有符号数和无符号数.对于运算的数来说,只要符合进位的情况,CF就置1.只要符合溢出的情况,OF就置1.但是后续 ...
- kmeans 聚类 k 值优化
kmeans 中k值一直是个令人头疼的问题,这里提出几种优化策略. 手肘法 核心思想 1. 肉眼评价聚类好坏是看每类样本是否紧凑,称之为聚合程度: 2. 类别数越大,样本划分越精细,聚合程度越高,当类 ...
- HNUSTOJ 1601:名字缩写
1601: 名字缩写 时间限制: 1 Sec 内存限制: 128 MB 提交: 288 解决: 80 [提交][状态][讨论版] 题目描述 Noname老师有一个班的学生名字要写,但是他太懒了,想 ...
- css兼容问题收集+部分效果收集+css重置
1.居中问题 div里的内容,IE默认为居中,而FF默认为左对齐,可以尝试增加代码margin: 0 auto; 2.高度问题 两上下排列或嵌套的div,上面的div设置高度(height),如果di ...
- git Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
只要把那个ip地址添加进hosts列表中就可解决. 参见:https://blog.csdn.net/hunhun1122/article/details/79752125
- pL/Sql插入语句时报错,对表空间没有权限 对表空间 'USERS' 无权限
进入dba为其授予权限:sqlplus sys/admin as sysdba; 为用户授予权限即可 grant unlimited tablespace to username;
- 3.17内存,进程,rpm和yum,python编译安装
一.内存 前面说过内存有寄存器.高速缓存和内存条 但在实际情况中有些文件比较大,内存不足以读取其内容,并且大部分内容不是被立即使用,所以有了交换分区,即用硬盘空间临时存储相关部分,当作缓存,这部分就是 ...
- Windows Neovim
配置文件路径C:\Users\UserName\AppData\Local\nvim\init.vim Vim-plug配置文件路径:C:\Users\UserName\AppData\Local ...
- 费用流+SPFA ||【模板】最小费用最大流
题面:[模板]最小费用最大流 代码: #include<cstdio> #include<cstring> #include<iostream> #include& ...