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 ...
随机推荐
- Python 线程,进程
Threading用于提供线程相关的操作,线程是应用程序中工作的最小单元 线程不能实现多并发 只能实现伪并发 每次工作 只能是一个线程完成 由于python解释器 原生是c 原生线程 底层都会有一把 ...
- hibernate ——helloWorld程序(annotation配置)
在 <hibernate ——helloWorld程序(XML配置)>基础上,修改.添加部分文件: 1.Teacher类和Teacher表 package com.pt.hiberna ...
- asp:cookies的属性
Expires – 过期时间.指定cookie的生命期.具体是值是过期日期.如果想让cookie的存在期限超过当前浏览器会话时间,就必须使用这个属性.当过了到期日期时,浏览器就可以删除cookie文件 ...
- Android OpenGL ES(五)GLSurfaceView .
Android OpenGL ES 相关的包主要定义在 javax.microedition.khronos.opengles GL 绘图指令 javax.microedition.khrono ...
- SSH整合环境下Spring配置文件的配置
applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans x ...
- sql trim()函数去掉两头空格
1.sql trim()函数去掉两头空格 sql语法中没有直接去除两头空格的函数,但有ltrim()去除左空格rtrim()去除右空格. 合起来用就是sql的trim()函数,即select ltri ...
- php截取中文字符串,英文字符串,中英文字符串长度的方法
今天学习了php函数截取中文字符串,英文字符串,中英文字符串的函数使用方法.对中英文截取方法不理解,此处先做记录. PHP自带的函数如strlen().mb_strlen()都是通过计算字符串所占字节 ...
- HDU - 5234 Happy birthday
Problem Description Today is Gorwin’s birthday. So her mother want to realize her a wish. Gorwin say ...
- 9个Console控制台命令(转载)
一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...
- 教你用CSS代码写出的各种形状图形
做网页设计时经常要用到各种形状的图形,对于规则的图形很简单,但是对于不规则的图形,一般我们都是用图片,今天就在这里教大家怎样用css代码写出各种规则不同的图形 1.正方形 #square {width ...