题目链接

题意:

  给一个数n, 每次操作是随机的选择一个[1,N]区间内能够被n整除的数进行除法, 然后得到一个新的n。

  问n变成1时的期望操作次数。

    

思路:

  设E[n] 为 当数为x时, 变成 1 期望的次数, 则有转移方程。

  E[n] = sigma E[n / x[i]] / k + 1(x[i] 为能被n被整除的数), k为n在区间[1,n]能被n整除的个数。

  化简:E[n] = E[n] / k + sigma E[n / x[i]] / k + 1

        = k * (sigmaE[n / x[i]] / k + 1) / (k - 1)

        = (sigmaE[n / x[i]] + k) / (k - 1)。

代码:

  

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAXN 100010
#define MOD 1000000007
#define eps 1e-6
int n;
double f[MAXN];
bool vis[MAXN];
vector <int> g[MAXN];
void init()
{
for(int i = ; i < MAXN; i ++)
for(int j = ; j * i < MAXN; j ++)
g[j * i].push_back(i); f[] = ;
memset(vis, false, sizeof(vis));
}
double dp(int x)
{
if(x == ) return 0.0;
if(vis[x]) return f[x];
vis[x] = true;
double& ans = f[x];
ans = 0.0;
for(int i = ; i < g[x].size(); i ++)
ans += dp(x/g[x][i]);
ans += (g[x].size() + 1.0);
ans /= g[x].size();
return ans;
} int main()
{
int T;
int kcase = ;
init();
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
printf("Case %d: %.7lf\n", ++ kcase, dp(n));
}
return ;
}

LightOJ_1038 Race to 1 Again的更多相关文章

  1. Promise.race

    [Promise.race] 返回最先完成的promise var p1 = new Promise(function(resolve, reject) { setTimeout(resolve, 5 ...

  2. golang中的race检测

    golang中的race检测 由于golang中的go是非常方便的,加上函数又非常容易隐藏go. 所以很多时候,当我们写出一个程序的时候,我们并不知道这个程序在并发情况下会不会出现什么问题. 所以在本 ...

  3. 【BZOJ-2599】Race 点分治

    2599: [IOI2011]Race Time Limit: 70 Sec  Memory Limit: 128 MBSubmit: 2590  Solved: 769[Submit][Status ...

  4. hdu 4123 Bob’s Race 树的直径+rmq+尺取

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Probl ...

  5. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  6. 【多线程同步案例】Race Condition引起的性能问题

    Race Condition(也叫做资源竞争),是多线程编程中比较头疼的问题.特别是Java多线程模型当中,经常会因为多个线程同时访问相同的共享数据,而造成数据的不一致性.为了解决这个问题,通常来说需 ...

  7. Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm

    C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...

  8. HDU 4123 Bob’s Race 树的直径 RMQ

    Bob’s Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=41 ...

  9. [LOJ 1038] Race to 1 Again

    C - Race to 1 Again Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu D ...

随机推荐

  1. css3 -&gt; 多栏布局

    在进行多栏布局时.使用bootstrap的栅格系统能够非常轻松的实现效果,事实上css3本身也提供了多兰布局的功能. 比方,我们在一个section标签内填充了非常多内容.同一时候希望内容可以显示成三 ...

  2. MachineKey

    我是在收到用户发来的这个错误信息的截图后才认识到什么是MachineKey的. 有关MachineKey的概念.MachineKey的生成以及web.config文件里的配置,网上一搜一大堆,为了方便 ...

  3. 设计模式 - 观察者模式(Observer Pattern) 详细说明

    观察者模式(Observer Pattern) 详细说明 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26583157 版权全部 ...

  4. CCProgressTimer用法

    bool HelloWorld::init(){ if ( !CCLayerColor::initWithColor(ccc4(255, 255, 2555, 255))){ return false ...

  5. Load resources from classpath in Java--reference

    In general classpath is the path where JVM can find .class files and resources of your application a ...

  6. Oracle 设置日志模式

    在NOARCHIVELOG模式下启动和运行一个数据库. 确定闪回恢复区的位置和归档日志目标目录的位置. 步骤一 为归档的重做日志配置FRA和单独的归档日志目标. 首先,设置FRA参数DB_RECOVE ...

  7. ubuntu 14.04/15.10 安装基于eclipse的android app开发环境

    一开始是装了ubuntu15.10,不知道是我的x200机器太old还是iso镜像有问题,总是各种莫名的引导不起来.有时候刚刚装好的干净系统,只install了一个vim和openssh,重启,然后就 ...

  8. Binding 中 Elementname,Source,RelativeSource 三种绑定的方式

    在WPF应用的开发过程中Binding是一个非常重要的部分. 在实际开发过程中Binding的不同种写法达到的效果相同但事实是存在很大区别的. 这里将实际中碰到过的问题做下汇总记录和理解. 1. so ...

  9. bootstrap学习和使用的经验总结

    第一肯定是下载 然后就是目录介绍,因为bootstrap是个轻量级的框架,目录不是很多,所以很容易理解,主要有用的就是三个文件,bootstrap.js,bootstrap.css,bootstrap ...

  10. [Mime] QuotedPrintableEncoding帮助类 (转载)

    点击下载 QuotedPrintableEncoding.rar 这个类是关于QuotedPrintableEncoding的帮助类看下面代码吧 /// <summary> /// 类说明 ...