Codeforces 621C Wet Shark and Flowers
来源:互联网 发布:轮询调度算法 编辑:程序博客网 时间:2024/06/05 00:07
题意:
一群鲨鱼围成一圈,Wet Shark说个质数p,每个鲨鱼在一定范围内选个数,如果两个相邻的鲨鱼选的数的乘积能被p整除,则每个鲨鱼都将得到1000元,求鲨鱼们最终得到钱数的期望。
分析:
比赛时乱七八糟的写,一直错,重新读题才注意到题目中说的:
If for any pair of neighbouring sharks i and j the product si·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.
只看相邻的两条鲨鱼,所以对于每条鲨鱼,只需看他和他前一条鲨鱼的数值范围大小以及范围内p的倍数的个数,转化为概率,分两种情况考虑:
- 两条鱼选的数都是p的倍数
- 一条鱼选的是p的倍数,另一条不是
代码:
#include<cstdio>#include<iostream>#include<cmath>#include<iomanip>using namespace std;const int maxn = 100005, INF=0x3fffffff;typedef long long ll;double f[maxn];int main (void){ int n;ll p; ll l,r; ll total = 1, cnt; scanf("%d%I64d",&n,&p); for(int i = 1; i <= n; i++){ scanf("%I64d%I64d",&l,&r); cnt = r/p - l/p; if(l%p == 0) cnt++; f[i]=(double)cnt/(r - l+1); } f[0] = f[n]; double ans = 0.0; for(int i = 1; i <= n; i++) ans += 1000*(f[i]*f[i-1] + (1-f[i])*f[i-1]+(1-f[i-1])*f[i]); printf("%.10lf\n",(double)ans*2); return 0;}
仔细读题!!别再马虎了!!心疼时间和分数。。。
0 0
- Codeforces 621C Wet Shark and Flowers
- CodeForces 621C Wet Shark and Flowers
- Codeforces 621C Wet Shark and Flowers 【期望】
- 【概率与期望】[CodeForces - 621C]Wet Shark and Flowers
- CodeForces 621 C. Wet Shark and Flowers(期望)
- Codeforces 621B Wet Shark and Flowers
- 621C. Wet Shark and Flowers【概率】
- codeforce 621C Wet Shark and Flowers
- Codeforces Round #341 (Div. 2) C. Wet Shark and Flowers
- Codeforces #341 C. Wet Shark and Flowers 概率论
- Codeforces Round #341 (Div. 2)--C. Wet Shark and Flowers
- Codeforces Round #341 (Div. 2)C. Wet Shark and Flowers
- Codeforces #341 div2 C.Wet Shark and Flowers(概率)
- Codeforces Round #341 (Div. 2)-C. Wet Shark and Flowers
- 文章标题HDU 4355:codeforces 621C:Wet Shark and Flowers(水)
- Codeforce 题目621C Wet Shark and Flowers(期望)
- 612 C. Wet Shark and Flowers
- CF621C - Wet Shark and Flowers
- java中值得注意的
- spring boot 工程如何生成 gradle wrapper
- Oracle 出现锁表问题解决步骤(以前写的一份故障排查报告)
- 新方法-根据上排给出十个数,在其下排填出对应的十个数
- c++ ActiveX基础1:使用VS2010创建MFC ActiveX工程项目
- Codeforces 621C Wet Shark and Flowers
- apache2 [warn] NameVirtualHost *:80 has no VirtualHosts的解决方法
- Oracle 同实例中两个不同owner的表字段比较脚本
- CAS+SSO原理浅谈
- iOS开发第三方介绍之一Masonry
- ie多账号登录问题
- linux系统管理及配置
- iOS 如何连接打印机
- Android中利用手机抓包的方法,经典篇