CodeForces 621C Wet Shark and Flowers
方法可以转化一下,先计算每一个鲨鱼在自己范围内的数能被所给素数整除的个数有几个,从而得到能被整除的概率,设为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的更多相关文章
- codeforce 621C Wet Shark and Flowers
题意:输入个n和质数p,n个区间,每个区间可以等概率的任选一个数,如果选的这个区间和它下个区间选的数的积是p的倍数的话(n的下个是1),就挣2000,问挣的期望 思路:整体的期望可以分成每对之间的期望 ...
- Wet Shark and Flowers(思维)
C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【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 ...
- 【矩阵乘法优化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 ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- 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 ...
- Codeforces Round #341 Div.2 C. Wet Shark and Flowers
题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...
- CodeForces 621B Wet Shark and Bishops
记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...
- CodeForces 621A Wet Shark and Odd and Even
水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #inclu ...
随机推荐
- Django Template模板
Django Template 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. 下面我们来调用html views def ind ...
- asp的RegExp对象正则表达式功能用法
RegExp对象提供简单的正则表达式支持功能. RegExp对象的用法: 以下为引用的内容: Function RegExpTest(patrn, strng) Dim regEx, Match, M ...
- MVC 和 MVVM
MVVM MVVM 是 Model-View-ViewModel 的简写,MVVM 模式和 MVC 模式一样,主要目的是分离视图(View)和模型(Model) MVC 回顾 MVC 结构图 MVC ...
- wpf资源嵌套,一个资源引用另外一个资源,被引用的资源应该声明在前面
在wpf的XAML的Window.Resources中,一个资源引用另外一个资源,出现如下错误: “错误 1 “{DependencyProperty.UnsetValue}”不是 Setter 上“ ...
- UVA 10308 Roads in the North
input u1 v1 w1 u2 v2 w2 ... un vn wn 1<=vi,ui<=n+1 /n output 距离最远的两个点的距离 做法:一颗全连通且只有一条路从一个顶点到达 ...
- JS限制 获取动太ID,播放视频
JS限制textarea字数 function textdown(e) {textevent = e ; ) { return; } ) { alert("大侠,我手机屏幕小,先输入这么多字 ...
- xcconfig 文件配置文件 问题
与公司 QA 聊天,已不止一次被吐槽说移动端从开发环境转到生产环境时,还要靠修改代码来配置对应的环境参数.她认为,从 App 转测试之后,就不应该再修改代码,可以把所有的环境配置都整合到配置文件中,这 ...
- HDU1162-Eddy's picture(最小生成树)
Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...
- Mysql主从备份、主主备份
简单介绍mysql双机,多机异地热备简单原理实战. 双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做 ...
- 十二月总结-and-2016年终总结
回顾 今天是2016的最后一天了,所以今天来做一个年终总结是最好不过的了.各种期末考试随着而来,也就意味着在工大的第一个学期马上结束了.回顾一下这一年所获得或者失去的一些东西: 2月份在家焦虑的等待着 ...