概率论
题目:In 0th day, there are n-1 people and 1 bloodsucker. Every day, two and only two of them meet. Nothing will happen if they are of the same species, that is, a people meets a people or a bloodsucker meets a bloodsucker. Otherwise, people may be transformed into bloodsucker with probability p. Sooner or later(D days), all people will be turned into bloodsucker. Calculate the mathematical expectation of D.

Input
The number of test cases (T, T ≤ 100) is given in the first line of the input. Each case consists of an integer n and a float number p (1 ≤ n < 100000, 0 < p ≤ 1, accurate to 3 digits after decimal point), separated by spaces.

Output
For each case, you should output the expectation(3 digits after the decimal point) in a single line.

Sample Input
1
2 1

Sample Output
1.000
题意:n-1人,1吸血鬼,每天有两个人遇见,只有人和吸血鬼遇见会触发概率事件,同化吸血鬼,全部同化的期望。

#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define ll long long
using namespace std;
double f[100010],g[100010],a[100010];
int main()
{int n,t;double s1,s2,s3,d;scanf("%d",&n);while(n--){scanf("%d%lf",&t,&d);f[t]=0;for(int i=t-1;i>=1;i--){s1=(double)t*(t-1)/2;s2=(double)i*(t-i);s3=s2/s1*d;f[i]=(f[i+1]*s3+1)/s3;}printf("%.3lf\n",f[1]);}return 0;
}

Bloodsucker ZOJ - 3551相关推荐

  1. ZOJ.3551.Bloodsucker(期望DP)

    题目链接 \(Description\) 有1个吸血鬼和n-1个人,每天有且只会有两个人/吸血鬼相遇,如果是人与吸血鬼相遇,那个人会有p的概率变成吸血鬼:否则什么也不发生.求n个都变成吸血鬼的期望天数 ...

  2. UVa在线比赛单题汇总-----DP专题

    动态规划基础 例题 LA 3882 UVa 3882 - And Then There Was One 递推------------无力orz UVa 10635 10635 - Prince and ...

  3. zoj 3351 Bloodsucker(概率 dp)

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4530 dp[i]表示现在存在i个吸血鬼要达成目标(全为吸血鬼)天数的数学 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  6. zoj 1204 Additive equations

    ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...

  7. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  8. 模拟 ZOJ 3878 Convert QWERTY to Dvorak

    题目传送门 1 /* 2 模拟:手敲map一一映射,累! 3 除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:) 4 */ 5 #include <cstdio> 6 ...

  9. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 1 /* 2 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 3 矩阵连乘积问题,DP解决:状态转移方程: 4 dp[i][j] = min (dp[i][k] + dp[k+1] ...

  10. ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)

    ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...

最新文章

  1. MySQL 学习笔记(9)— 事务控制语句、事务属性以及并发和隔离级别
  2. Unshielded Twisted Pair - CAT5, 5e 6
  3. CTFshow php特性 web104
  4. Java基础day4
  5. Mysql的一些问题
  6. Unity引擎及编辑器C#源代码发布
  7. 透明地持久保存并从数据库中检索加密的数据
  8. json 对象 数组
  9. OpenCV:H1.type() == H2.type() H1.depth() == CV_32F
  10. c语言 指针_初识C语言指针
  11. 宅男程序员给老婆的计算机课程之4:SQL vs NoSQL
  12. android 本地日历,Android日历提供商:如何删除自己的本地日历?
  13. BOSS直聘:2020一季度平均招聘薪资8609元 同比增长2.8%
  14. Q134:PBRT-V3,次表面散射(Subsurface Scattering)(15.5章节)
  15. vue中select选择框的监听事件
  16. 图像的峰值信噪比(PSNR)的计算方法
  17. 爬虫爬取电影天堂电影链接
  18. 《东周列国志》第二十九回 晋惠公大诛群臣 管夷吾病榻论相
  19. 2021年电工(初级)考试题库及电工(初级)最新解析
  20. 用python画环形图

热门文章

  1. 初等数论及python应用
  2. ZYNQ-AXI DMA IP简介
  3. HTML个人简历代码模板(静态页面)
  4. Html5 打砖块游戏,加入道具和速通模式(含源码)
  5. Amlogic Linux系列(四) 视频解码分析2
  6. OpenGL ES 2.0 for Android教程(三):编译着色器并绘制到屏幕
  7. Coursera吴恩达《构建机器学习项目》课程笔记(2)-- 机器学习策略(下)
  8. html中fixed属性,css中fixed是什么意思?
  9. 理性分析三星盖乐世炸弹7
  10. 查看漏洞库平台有哪些?