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 ...
随机推荐
- sql server 数据库导出表里所有数据成insert 语句
有时候,我们想把数据库的某张表里的所有数据导入到另外一个数据库或另外一台计算机上的数据库,对于sql server有这样的一种方法 下面我以sql server 2008 R2,数据库是Northwi ...
- ubuntu 安装LNMP
How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04 PostedJune 13, 2012 802.8kviews ...
- 1.2 sikuli API
sikuli API网站:http://nightly.sikuli.de/docs/index.html eclipse中如果要用到相应的 sikuli 功能,可以查看API ,然后import相应 ...
- web项目docker化的两种方法
标题所讲的两种方法其实就是创建docker镜像的两种方法 第一种:启动镜像后进入容器中操作,将需要的软件或者项目移动到容器中,安装或者部署,然后退出即可 第二种:编写dockerfile,将需要的镜像 ...
- scrollView的bounds
如果scrollView的contentoffset为(100,0) 那么scrollView的bounds就是(100,y,w,h)
- ssh登录nat模式的VMware虚拟机
有时候本地PC是固定IP上网方式且无多余IP,而我们又希望使用putty登陆VMware中的虚拟机且虚拟机可以上外网,那么这时候就可以使用端口映射. 1.本地环境简述 本地PC IP:192.168. ...
- 最短路<dijk>
题意: 有n个城市,有m条路,给出每条路的出发和结束的城市及长度,求从第一个城市到最后一个城市的最短路.按格式输出. power oj 2443 题解: 标准dijk算法. #include<c ...
- java vector 和ArrayList的区别
相同点: 1.都是使用数组存储数据 不同点: 1.Vector是显示安全的,ArrayList是线程不安全的 Vector部分代码: public synchronized boolean add(E ...
- android 中ImageButton按下改变背景图片的效果
最近在做一个app的登陆界面,才发现原来认为很简单的UI效果,其实背后却蕴含的知识很多,积累一个算一个吧. 实现方法有两种:一种是添加代码,一种是配置xml文件. 方法一:代码添加 ImageButt ...
- 一个完整的项目中,需要的基本gulp
一个完整的项目需要使用gulp的多种功能,包括—— (1)加载各种需要的插件 var concat=require('gulp'); var clean=require(''gulp); 等等.需要的 ...