Article

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5236

Description

As the term is going to end, DRD begins to write his final article.

DRD
uses the famous Macrohard's software, World, to write his article.
Unfortunately this software is rather unstable, and it always crashes.
DRD needs to write n characters in his article. He can press a key to input a character at time i+0.1, where i is an integer equal or greater than 0. But at every time i−0.1 for integer i strictly greater than 0, World might crash with probability p
and DRD loses his work, so he maybe has to restart from his latest
saved article. To prevent write it again and again, DRD can press Ctrl-S
to save his document at time i. Due to the strange keyboard DRD uses, to press Ctrl-S he needs to press x characters. If DRD has input his total article, he has to press Ctrl-S to save the document.

Since
World crashes too often, now he is asking his friend ATM for the
optimal strategy to input his article. A strategy is measured by its
expectation keys DRD needs to press.

Note that DRD can press a key at fast enough speed.

Input

First line: an positive integer 0≤T≤20 indicating the number of cases.
Next T lines: each line has a positive integer n≤105, a positive real 0.1≤p≤0.9, and a positive integer x≤100.

Output

For each test case: output ''Case #k: ans'' (without quotes), where k is the number of the test cases, and ans is the expectation of keys of the optimal strategy.
Your answer is considered correct if and only if the absolute error or the relative error is smaller than 10−6.

Sample Input

2 1 0.5 2 2 0.4 2

Sample Output

Case #1: 4.000000
Case #2: 6.444444

HINT

题意

要求输入一篇N个字符的文章,对所有非负整数i:

每到第i+0.1秒时可以输入一个文章字符

每到第i+0.9秒时有P的概率崩溃(回到开头或者上一个存盘点)

每到第i秒有一次机会可以选择按下X个键存盘,或者不存

打印完整篇文章之后必须存盘一次才算完成

输入多组N,P,X选择最佳策略使得输入完整篇文章时候按键的期望最小,输出此期望

题解:

首先我们先分析不考虑保存的情况的dp

dp[i]=dp[i-1]+p*(1+dp[i])+(1-p);

敲出i个字符, 首先得敲出i-1个字符, 所以有第一部分的dp[i-1]; 然后敲下一个字符时, 有两种可能, p概率会丢失, (1-p)概率不会丢失, 对于丢失的情况就还得重新敲dp[i]次了(期望次数), 不丢失的情况就只有一次就成功了, 所以是(1-p) * 1。

所以化简为: dp[i] = (dp[i-1] + 1) / ( 1- p)

然后我们就考虑保存了,我们枚举保存的次数

然后很显然,我们得均匀的保存,这样子贪心就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//**************************************************************************************
double f[maxn];
double p,ans;
int n,x;
void init()
{
scanf("%d%lf%d",&n,&p,&x);
}
void solve()
{
init();
for(int i=;i<=n;i++)
f[i]=(f[i-]+)/(-p);
ans=inf;
for(int i=;i<=n;i++)
{
int cnt=n%i;
ans=min(ans,f[n/i+]*cnt+f[n/i]*(i-cnt)+x*i);
}
printf("%.6lf\n",ans);
}
int main()
{
//test;
int t=read();
for(int cas=;cas<=t;cas++)
{
printf("Case #%d: ",cas);
solve();
}
}

hdu 5236 Article 概率dp的更多相关文章

  1. HDU 5236 Article (概率DP+贪心)

    题意:要求输入一篇N个字符的文章,对所有非负整数i:每到第i+0.1秒时可以输入一个文章字符,每到第i+0.9秒时有P的概率崩溃(回到开头或者上一个存盘点) 每到第i秒有一次机会可以选择按下X个键存盘 ...

  2. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

  3. HDU - 1099 - Lottery - 概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...

  4. HDU 4405 【概率dp】

    题意: 飞行棋,从0出发要求到n或者大于n的步数的期望.每一步可以投一下筛子,前进相应的步数,筛子是常见的6面筛子. 但是有些地方可以从a飞到大于a的b,并且保证每个a只能对应一个b,而且可以连续飞, ...

  5. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  6. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

  7. [HDU 4089]Activation[概率DP]

    题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...

  8. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  9. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

随机推荐

  1. js原生读取json

    function showJson(){ var test; if(window.XMLHttpRequest){ test = new XMLHttpRequest(); }else if(wind ...

  2. rdpClient

    https://github.com/jean343/RPI-GPU-rdpClient https://github.com/Nullstr1ng/MultiRDPClient.NET https: ...

  3. 包装类、基本数据类型及String类之间的相互转换

    包装类:8种基本数据类型对应一个类,此类即为包装类 一.基本数据类型 包装类 及String之间的转换 1.基本数据类型转化为包装类:调用包装类的构造器      int i=10;     Inte ...

  4. FineReport——JS二次开发(分页预览)

    BS访问某个cpt模板,报表servlet将会将cpt文件解析成对应的html,报表内容最终转换为一个table,位于id=content-container的div中. 在模板和html页面中,他们 ...

  5. kafka 设置消费者线程数

    http://blog.csdn.net/derekjiang/article/details/9053863 分布式发布订阅消息系统 Kafka 架构设计 - 目前见到的最好的Kafka中文文章 M ...

  6. Math.random易于记忆理解

    产生随机数 Math.random*(Max-Min)+Min

  7. CocoaPods第三方类库依赖管理

    安装cocoapods   1.移除ruby的源地址 gem sources --remove https://rubygems.org/   2.添加ruby的源地址 gem sources -a ...

  8. grid+report 怎么在项目中使用

    grid+report 的例子很丰富,首先看你所用对应编程语言的例子.参考帮助的“产品介绍->快速入门指导”部分.根据快速入门指导中的说明,先把例子程序运行. 例子分两部分:1.报表模板例子,主 ...

  9. 深度学习方法(六):神经网络weight参数怎么初始化

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 神经网络,或者深度学习算法的参数初始 ...

  10. WordPress主循环(The Loop)函数have_posts(),the_post()详解

    WordPress中调用文章标题是the_title();调用文章内容时用到the_content();调用文章的作者时用到the_author();等等这些函数,都需要在主循环中使用,下面就介绍一下 ...