要点

  • 都在注释里了
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std; typedef double db;
const int maxn = 1e5 + 5;
int n;
db l, v1, v2;
db a[maxn], ans[maxn]; db val(db x) {//make the value on the loop
while (x < 0) x += 2 * l;
return x;
} int main() {
scanf("%d %lf %lf %lf", &n, &l, &v1, &v2);
db len = v2 * l / (v1 + v2);
//实数环上的差分,求2*l长度的环上被长度len包括的点的个数的概率
vector<pair<db, int>> v;
for (int i = 1; i <= n; i++) {
scanf("%lf", &a[i]);//点的位置
v.emplace_back(val(a[i] - len), 1);//start, cnt should +1
v.emplace_back(a[i], -1);//end, cnt should -1
} v.emplace_back(2 * l, 0);//在0处断开环,形成一个终点
sort(v.begin(), v.end()); int cnt = 0;
db cur = 0.0;//起点 for (int i = 1; i <= n; i++) {
if (a[i] < len) cnt++;//初始状态的数量
else break;
}
for (auto i : v) {
ans[cnt] += i.first - cur;
cur = i.first;
cnt += i.second;
} for (int i = 0; i <= n; i++)
printf("%.20lf\n", ans[i] / 2 / l);
}

Codeforces 163C(实数环上的差分计数)的更多相关文章

  1. Codeforces 588E. A Simple Task (线段树+计数排序思想)

    题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...

  2. Codeforces 225C Barcode(矩阵上DP)

    题目链接:http://codeforces.com/contest/225/problem/C 题目大意: 给出一个矩阵,只有两种字符'.'和'#',问最少修改多少个点才能让每一列的字符一致,且字符 ...

  3. Codeforces 382E Ksenia and Combinatorics 【组合计数】*

    Codeforces 382E Ksenia and Combinatorics Ksenia has her winter exams. Today she is learning combinat ...

  4. HDU 4305 Lightning(计算几何,判断点在线段上,生成树计数)

    Lightning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. codeforces 816B Karen and Coffee (差分思想)

    题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可 ...

  6. CodeForces - 587E[线段树+线性基+差分] ->(线段树维护区间合并线性基)

    题意:给你一个数组,有两种操作,一种区间xor一个值,一个是查询区间xor的结果的种类数 做法一:对于一个给定的区间,我们可以通过求解线性基的方式求出结果的种类数,而现在只不过将其放在线树上维护区间线 ...

  7. Codeforces 772D - Varying Kibibits(高维差分+二项式定理维护 k 次方和)

    Codeforces 题目传送门 & 洛谷题目传送门 首先很容易注意到一件事,那就是对于所有 \(f(S)\) 可能成为 \(x\) 的集合 \(S\),必定有 \(\forall y\in ...

  8. Codeforces 451E Devu and Flowers(组合计数)

    题目地址 在WFU(不是大学简称)第二次比赛中做到了这道题.高中阶段参加过数竞的同学手算这样的题简直不能更轻松,只是套一个容斥原理公式就可以.而其实这个过程放到编程语言中来实现也没有那么的复杂,不过为 ...

  9. Codeforces Round #258 D Count Good Substrings --计数

    题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...

随机推荐

  1. 农业公司flash动画模板

    农业公司flash动画素材下载模板是一款绿色水果蔬菜种植企业的flash动画模板. 下载:http://www.huiyi8.com/sc/10576.html

  2. 时尚设计div+css免费模板

    时尚设计div+css免费网页模板,时尚设计,div+css. http://www.huiyi8.com/moban/

  3. html5--1.16 内联框架

    html5--1.16 内联框架 学习要点: 1.iframe内联框架2.综合实例1 1.iframe内联框架 1.iframe元素用来在文档中添加一个内联框架. 2.iframe为body元素的子元 ...

  4. not in和not exist的区别(转)

    in和exists in 是把外表和内表作hash 连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.一直以来认为exists比in效率高的说法是不准确的. 如果查询的两个 ...

  5. hdu5776sum

    题目连接  抽屉原理:如果现在有3个苹果,放进2个抽屉,那么至少有一个抽屉里面会有两个苹果 抽屉原理的运用 现在假设有一个正整数序列a1,a2,a3,a4.....an,试证明我们一定能够找到一段连续 ...

  6. listen 68 Theoretical Physicist Stephen Hawking Dies at 76

    World-renowned British physicist Stephen Hawking, who sought to understand a range of cosmic topics ...

  7. listen 61

    Multiple Stresses Killed Snail Memory Stress sucks. It can affect your body and mind. Previous resea ...

  8. linux进程学习笔记

    学习了linux下的进程,觉得应该整理一下,忘得差不多了,顺便回顾一下. 学而时习之,不亦说乎~~ 进程笔记 ,什么是进程? The Single UNIX Specification, Versio ...

  9. 理解YOLOv2训练过程中输出参数含义

    原英文地址: https://timebutt.github.io/static/understanding-yolov2-training-output/ 最近有人问起在YOLOv2训练过程中输出在 ...

  10. [JSOI 2018] 潜入行动

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5314 [算法] 考虑dp , 用f[i][j][0 / 1][0 / 1]表示以i为 ...