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 ...
随机推荐
- wpf绑定之格式化日期
只显示年月日: StringFormat='{}{0:yyyy/MM/dd}' 又或者: StringFormat='{}{0:yyyy年MM月dd日 dddd HH:mm:ss}',Converte ...
- ubuntu 安装LNMP
How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04 PostedJune 13, 2012 802.8kviews ...
- 【转】使用ThinkPHP必须掌握的调试方法
经常看到有人问到findAll的返回数据类型是什么之类的问题,以及出错了不知道什么原因的情况,其实还是没有熟悉ThinkPHP内置的调试手段和方法,抛开IDE本身自带的调试方式不说,如果你正在用或者打 ...
- oracle的row_number()和rownum
row_number() 函数和rownum的介绍: 1.row_number() 方法的格式: row_number()over([partition by col1] order by col2) ...
- NullPointerException
if(userName.equals("zhansan")){} 可能会报空指针异常
- .gitigore 相关
为什么要配置.gitigore 在我们使用git的过程当中,不是任何文件都需要commit到本地或者远程仓库的,比如一些三方库文件.那么作为一个git新手,很多人不知道如何配置.gitignore文件 ...
- Windows API 之 GetStartupInfo 、CreateProcess
GetStartupInfo 参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms683230%28v=vs.85%29.asp ...
- 未能加载文件或程序集 Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0 解决 亲测
项目打开winform程序做的某些窗体时报错: ************* 异常文本 ************** System.Reflection.TargetInvocationExceptio ...
- 求交集,差集,并集,善用java的set
当有题目有求这些结果时,使用集合数据结构还是很快的.需要考虑的是,注意map和set的区别. public static void main(String[] args) { Set<Integ ...
- hdu_5213_Lucky(莫队算法+容斥定理)
题目连接:hdu_5213_Lucky 题意:给你n个数,一个K,m个询问,每个询问有l1,r1,l2,r2两个区间,让你选取两个数x,y,x,y的位置为xi,yi,满足l1<=xi<=r ...