HDU 5236 Article [概率DP]

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  characters in his article. He can press a key to input a character at time , where  is an integer equal or greater than 0. But at every time  for integer  strictly greater than 0, World might crash with probability  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 . Due to the strange keyboard DRD uses, to press Ctrl-S he needs to press  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  indicating the number of cases.
Next T lines: each line has a positive integer , a positive real , and a positive integer

Output

For each test case: output ''Case #k: ans'' (without quotes), where  is the number of the test cases, and  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

解法

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
template <class T>
bool scanff(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
#define inf 1073741823
#define llinf 4611686018427387903LL
#define PI acos(-1.0)
#define lth (th<<1)
#define rth (th<<1|1)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)
#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)
#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mkp(a,b) make_pair(a,b)
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

double dp[1111];
int main(){
tdata{
int n;
double tx;
double p;
scanff(n);scanff(p);scanff(tx);
dp[0]=0.0;
int num=0;
rep(i,1,1000){
num++;
dp[i]=(dp[i-1]+1.0)/(1.0-p);
if(dp[i]>(llinf)/10.0)break;
}

int k=n/num+1;
double ans=llinf*1.0;
rep(i,k,n){
int len=n/i;
int x=n%i;
int y=i-x;
ans=min(ans,double(x)*dp[len+1]+double(y)*dp[len]+double(tx)*double(i));
}
printf("Case #%d: %lf\n",cas,ans);
}
}
/*
3 5 3
2 2 3
2 1 3
2 1 2
3 2 3 1
2 1 2

3 2 2
3 2 3 1
3 1 2 3

0 0 0
*/


• 本文已收录于以下专栏：

hdu 5236 Article 概率dp

• zp___waj
• 2017年04月29日 16:40
• 202

概率dp hdu 5236

• driver13
• 2015年11月10日 20:34
• 169

HDU 5236 Article

• Mr_Xujh
• 2015年06月12日 20:37
• 444

概率DP——HDU 5236

• FeBr2
• 2017年04月08日 21:05
• 262

hdu - 5236 Article（2015上海大都会赛）概率dp

Article Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...
• u010660276
• 2015年06月04日 21:25
• 1033

HDU 3366 Passage (概率DP）

Passage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...
• Interstellar_
• 2016年07月26日 19:29
• 836

Hdu 5236 Article（dp）

• 2015年06月12日 15:45
• 430

HDU4652Dice(概率DP)

HDU4652Dice(概率DP)2013 Multi-University Training Contest 5
• u013790563
• 2015年08月27日 15:01
• 743

【HDU5583 2015上海赛区L】【找规律 正难则反】LCM Walk 目标状态（x，y）哪些点走公倍数能走到它

LCM Walk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total S...
• snowy_smile
• 2015年11月28日 22:26
• 1442

HDU-4035 Maze （概率DP&&树形DP）

• idealism_xxm
• 2016年04月30日 12:44
• 398

举报原因： 您举报文章：HDU 5236 Article [概率DP] 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)