题意:输入个n和质数p,n个区间,每个区间可以等概率的任选一个数,如果选的这个区间和它下个区间选的数的积是p的倍数的话(n的下个是1),就挣2000,问挣的期望

思路:整体的期望可以分成每对之间的期望。期望=概率乘2000.

得到钱概率=1-得不到钱的概率

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define clc(a,b) memset(a,b,sizeof(a))
const int maxn=; double p[]; int main()
{
int n,m,l,r;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d%d",&l,&r);
int len=r/m-l/m;
if(l%m==)
len++;
p[i]=1.0-(double)len/(r-l+);
}
double ans=;
for(int i=;i<n;i++)
{
ans+=(1.0-p[i]*p[i+])*;
}
ans+=(1.0-p[n]*p[])*;
printf("%lf\n",ans);
}

codeforce 621C Wet Shark and Flowers的更多相关文章

  1. CodeForces 621C Wet Shark and Flowers

    方法可以转化一下,先计算每一个鲨鱼在自己范围内的数能被所给素数整除的个数有几个,从而得到能被整除的概率,设为f1,不能被整除的概率设为f2. 然后计算每相邻两只鲨鱼能获得钱的期望概率,f=w[id1] ...

  2. Wet Shark and Flowers(思维)

    C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

  4. Codeforces Round #341 Div.2 C. Wet Shark and Flowers

    题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...

  5. codeforce 621B Wet Shark and Bishops

    对角线 x1+y1=x2+y2 或者x1-y1=x2-y2 #include<iostream> #include<string> #include<algorithm& ...

  6. codeforce 621A Wet Shark and Odd and Even

    水 最大偶数和 #include<iostream> #include<string> #include<algorithm> #include<cstdli ...

  7. 【CodeForces 621A】Wet Shark and Odd and Even

    题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...

  8. B. Wet Shark and Bishops(思维)

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. cf-A. Wet Shark and Odd and Even(水)

    A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 说说对C语言指针的理解

    指针困扰了一些学习编程的人,或许你的老师会告诉你,指针比较难理解. 我当时被老师的话唬住所以学习指针那章的时候都没心情听课.(说得像讲别的内容时我听了似的,开玩笑) 导致了学习链表的时候各种卧槽. * ...

  2. UML_时序图画法

    UML建模之时序图(Sequence Diagram) 一.时序图简介(Brief introduction) 二.时序图元素(Sequence Diagram Elements) 角色(Actor) ...

  3. UIAlertView带textField

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"校验登录密码" message:@"" del ...

  4. 如何让listview列表为空时显示提示

    先在布局文件中声明一个TextView,再设置listview.setEmptyView(TextView).这样当listview中的数据为空时就会列表的位置就会显示textviw中的提示.

  5. C3p0的参数设置

    C3p0的参数设置:ComboPooledDataSource和BasicDataSource一样提供了一个用于关闭数据源的close()方法,这样我们就可以保证Spring容器关闭时数据源能够成功释 ...

  6. C#正则表达式之字符替换

    string strTest= "www.BaiDu.com",strRst=""; //忽略大小写,将strTest中的BaiDu替换为baidu Regex ...

  7. ASP.NET生命周期详解

    最近一直在学习ASP.NET MVC的生命周期,发现ASP.NET MVC是建立在ASP.NET Framework基础之上的,所以原来对于ASP.NET WebForm中的很多处理流程,如管道事件等 ...

  8. ***Java多线程发展简史

    http://blog.jobbole.com/28297/ 本文来自四火的博客(@RayChase),由@_Zhijun 推荐 这篇文章,大部分内容,是周五我做的一个关于如何进行Java多线程编程的 ...

  9. Android Service with Delphi 10 Seattle

    http://delphi.org/2015/09/minimalistic-android-service-with-delphi-10-seattle/ http://delphi.org/201 ...

  10. Android 获得屏幕的宽高度

    在View构造函数中获得屏幕的宽高 public class GameView extends View { public GameView(Context context) { Display d ...