lightoj1038
//Accepted 2860 KB 16 ms
//概率
//对于n,假设n变成1的期望步数为p(n)
//则p(n)=1/t*sum((1+p(d))) d|n
//解得:p(n)=1/(t-1)*(t+sum(p(d))) d|n d!=n;
//下面我们可以改造筛素数的方法,对于每个d,看他整除那些数
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
double f[imax_n];
int t[imax_n];
void pre()
{
;i<imax_n;i++)
{
f[i]=;
t[i]=;
}
f[]=;
;i<imax_n-;i++)
{
f[i]=(f[i]+)/t[i];
*i;j<imax_n-;j+=i)
{
f[j]+=+f[i];
t[j]++;
}
}
}
int n;
int main()
{
pre();
int T;
;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
printf("Case %d: %.6lf\n",++t,f[n]);
}
;
}
lightoj1038的更多相关文章
- lightoj1038(期望dp)
给定一个数字d,随机选择一个d的约数,然后让d除以这个约数,形成新的d,不断继续这个步骤,知道d=1为止, 要我们求将d变为1的期望次数 设d1,d2...dj是除以约数后,形成的行的d,且dj==d ...
- [LightOJ1038] Race to 1 Again
传送门:>出错啦< 题意:给你一个整数n,每一次可以随机选择一个n的因子x(包括1和它自己),让n除以x——不停重复此过程,直到n==1. 问n被除到1的期望次数. 解题思路: 今天刚学的 ...
- lightoj1038(数学期望dp)
题意:输入一个数N,N每次被它的任意一个因数所除 变成新的N 这样一直除下去 直到 N变为1 求变成1所期望的次数 解析: d[i] 代表从i除到1的期望步数:那么假设i一共有c个因子(包括1和本身) ...
- LightOJ 1038 Race to 1 Again(概率dp+期望)
https://vjudge.net/problem/LightOJ-1038 题意:给出一个数n,每次选择n的一个约数m,n=n/m,直到n=1,求次数的期望. 思路:d[i]表示将i这个数变成1的 ...
- LightOJ - 1038 Race to 1 Again —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1038 1038 - Race to 1 Again PDF (English) Statistics Foru ...
- [算法]概率与期望DP
前言 前两节主要针对题目分析,没时间的珂以跳过. 初步 首先举一道简单.经典的好题: [Lightoj1038]Race to 1 Again 懒得单独写,安利一下DennyQi同学的博客:https ...
随机推荐
- 获取AVCaptureSession samplebuffer 一像素的 rgb值
获取AVCaptureSession samplebuffer 一像素的 rgb值 typedef unsigned char byte; typedef struct RGBPixel{ byte ...
- Windows下快捷键
1.任务管理器ctrl+alt+delete 2.切换任务窗口alt+tab 3.命令行Win+R 命令: {打开任务管理器:taskmgr} {打开远程桌面连接:mstsc} 4.回到桌面Win+D ...
- url重写后发布出错问题
iis7 配置urlrewriter重写失效的问题 在IIS7下,如果使用微软的 URLRewriter 重写控件则需要在WEB.CONFIG中配置以下信息 第一个配置: <configSect ...
- hdu 2818 Building Block
Building Block Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Clone Graph [LeetCode]
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...
- 130. Surrounded Regions -- 被某字符包围的区域
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...
- Java 集合系列 01 总体框架
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...
- Help Me Escape (ZOJ 3640)
J - Help Me Escape Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB ...
- JAVA读取EXCEL文件异常Unable to recognize OLE stream
异常: jxl.read.biff.BiffException: Unable to recognize OLE stream at jxl.read.biff.CompoundFile.<in ...
- PHP获取当前页面的URL作为参数以供下一层的页面可以返回上一层页面
1.基础url的获取 #测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST'].&quo ...