题目链接: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的更多相关文章

  1. 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 ...

  2. Introduction to Probability (5) Continus random variable

    CONTINUOUS RANDOM VARIABLES AND PDFS  连续的随机变量,顾名思义.就是随机变量的取值范围是连续的值,比如汽车的速度.气温.假设我们要利用这些參数来建模.那么就须要引 ...

  3. Jmeter入门16 数据构造之随机数Random Variable & __Random函数

     接口测试有时参数使用随机数构造.jmeter添加随机数两种方式 1  添加配置 > Random Variable  2  __Random函数   ${__Random(1000,9999) ...

  4. Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...

  5. 【概率论】4-1:随机变量的期望(The Expectation of a Random Variable Part II)

    title: [概率论]4-1:随机变量的期望(The Expectation of a Random Variable Part II) categories: - Mathematic - Pro ...

  6. 【概率论】3-8:随机变量函数(Functions of a Random Variable)

    title: [概率论]3-8:随机变量函数(Functions of a Random Variable) categories: Mathematic Probability keywords: ...

  7. 【概率论】4-1:随机变量的期望(The Expectation of a Random Variable Part I)

    title: [概率论]4-1:随机变量的期望(The Expectation of a Random Variable Part I) categories: - Mathematic - Prob ...

  8. codeforces 442C C. Artem and Array(贪心)

    题目链接: C. Artem and Array time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

随机推荐

  1. H264 RTP包解析

    1.  预备 视频: 由一副副连续的图像构成,由于数据量比较大,因此为了节省带宽以及存储,就需要进行必要的压缩与解压缩,也就是编解码. h264裸码流: 对一个图像或者一个视频序列进行压缩,即产生码流 ...

  2. 码云与Git的使用

    码云注册和使用 网址:https://gitee.com 注册之后新建一个仓库 接下来安装Git 协同开发Git安装与使用 下载地址:https://gitforwindows.org 安装完成之后选 ...

  3. 线程中断:Thread类中interrupt()、interrupted()和 isInterrupted()方法详解

    首先看看官方说明: interrupt()方法 其作用是中断此线程(此线程不一定是当前线程,而是指调用该方法的Thread实例所代表的线程),但实际上只是给线程设置一个中断标志,线程仍会继续运行. i ...

  4. 1-ES简单介绍

    一.ES简单介绍 ES:Elastic Search,一个分布式.高扩展.高实时的搜索与数据分析引警.它可以准实时地快速存储.搜索.分析海量的数据. 1.ES实现原理 a.用户数据提交到ES数据库中 ...

  5. linux 深入应用 NFS

    以下实验大家用主机名来区分服务器端和客户端, 服务器端为 NFS_Server ip-192.168.1.4: 客户端为 NFS_Client ip-192.168.1.5: 实例一 将/tmp 分享 ...

  6. fpga ip

    原文地址:altera FIR ip核 license破解作者:王永刚Aether 在证书文件中添加一段: FEATURE 6AF7_0012 alterad 2035.12 permanent un ...

  7. EFL - Championship

    Swansea City       Charlton AthleticBristol CityLeeds UnitedPreston North EndWest Bromwich AlbionQue ...

  8. 将pip源更换到国内镜像

    将pip源更换到国内镜像用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s.幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2M ...

  9. gperftools尝试

    最近在找windows下比较好用的函数时间统计的库,听同事说gperftools是跨平台的,就下载下来尝试了一把.发现它确实实现了windows上可以调用的dll库文件(tcmalloc_minima ...

  10. Flutter-Radio單選框

    Container( child: Radio<String>( value: "男", activeColor: Colors.red,//激活時的顏色 groupV ...