方法可以转化一下,先计算每一个鲨鱼在自己范围内的数能被所给素数整除的个数有几个,从而得到能被整除的概率,设为f1,不能被整除的概率设为f2.

然后计算每相邻两只鲨鱼能获得钱的期望概率,f=w[id1].f1*w[id2].f2+w[id1].f2*w[id2].f1+w[id1].f1*w[id2].f1;

f*2000就是这两只鲨鱼能获得的期望金钱,然后枚举一下所有相邻的鲨鱼,累加即可。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=+;
struct X
{
int tot;//总共的个数
int t;//能被整除的个数
double f1;
double f2;
}w[maxn];
int n,p; int main()
{
scanf("%d%d",&n,&p);
for(int i=;i<n;i++)
{
int li,ri;
scanf("%d%d",&li,&ri);
int q1,q2;
q1=li/p;
if(q1*p<li) q1++;
q2=ri/p;
if(q2*p>ri) q2--;
if(q2<q1) w[i].t=;
else w[i].t=q2-q1+;
w[i].tot=ri-li+;
} for(int i=;i<n;i++)
{
w[i].f1=1.0*w[i].t/w[i].tot;
w[i].f2=1.0*(w[i].tot-w[i].t)/w[i].tot; // printf("%lf %lf\n",w[i].f1,w[i].f2);
} double ans=;
for(int i=;i<n;i++)
{
int id1=i;
int id2=(i+)%(n); double f=w[id1].f1*w[id2].f2+w[id1].f2*w[id2].f1+w[id1].f1*w[id2].f1;
// printf("%lf\n",f);
ans=ans+*f;
}
printf("%.5lf\n",ans);
return ;
}

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

  1. codeforce 621C Wet Shark and Flowers

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

  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. 【矩阵乘法优化dp】[Codeforces 621E] Wet Shark and Blocks

    http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds ...

  5. Codeforces 612B. Wet Shark and Bishops 模拟

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

  6. CODEFORCEs 621E. Wet Shark and Blocks

    E. Wet Shark and Blocks time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

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

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

  8. CodeForces 621B Wet Shark and Bishops

    记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...

  9. CodeForces 621A Wet Shark and Odd and Even

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #inclu ...

随机推荐

  1. gnome3

    http://askubuntu.com/questions/67753/how-do-i-add-an-application-to-the-dash https://wiki.gnome.org/ ...

  2. Mysql-左连接查询条件失效的解决办法

    on 后面不能 接and 要接where 这个条件才能判断成功 判断条件先后顺序,先判断主条件where,再判断条件on 如果是左连接on限制的就是右表,如果不为真则那一行的值为null,where限 ...

  3. 最佳死链接href= "#" VS href= "javascript:void(0);"

    href= "#" 熟悉hash跳转的同学都知道,只是一个hash跳转,跳转到页面的顶部,可以发现地址栏多了一个#,点击返回会返回本页面. href= "javascri ...

  4. js冒泡事件小解

    何为冒泡事件?简单来说事件就像一个水里的泡泡,先触发当前对象再触发其父元素,然后是父元素的父元素... eg: <div class="out" onclick= " ...

  5. Cookie 的设置和获取

    获取:var userName = getCookieValue("userName"); 设置:setCookie("userName",equpid,24, ...

  6. Android OpenGL ES(十二):三维坐标系及坐标变换初步 .

    OpenGL ES图形库最终的结果是在二维平面上显示3D物体(常称作模型Model)这是因为目前的打部分显示器还只能显示二维图形.但我们在构造3D模型时必须要有空间现象能力,所有对模型的描述还是使用三 ...

  7. poll和select

    都允许进程决定是否可以对一个或者多个打开的文件做非阻塞的读取或写入.这些调用也会阻塞进程,直到给定的文件描述符集合中的任何一个可读取或写入.常常用于那些要使用多个输入或输出流而又不会阻塞与其中任意一个 ...

  8. Viewpager实现网络图片的轮播

    //主意:里面用到了第三方的Xutils.jar包和Imageloader.jar包还用到了访问网络,所以要加网络权限 <uses-permission android:name="a ...

  9. 在Activity之间使用Intent传值和Bundle传值的区别和方式

    两者本质上没有任何区别.Bundle只是一个信息的载体 将内部的内容以键值对组织 Intent负责Activity之间的交互 自己是带有一个Bundle的Intent.putExtras(Bundle ...

  10. sizeof和strlen

    1.char *str="0123456789"; 这个变量是存在静态区域的,是delete不了的,是内存自动分配的,可以用strlen(str)得到其长度,不能用sizeof. ...