上海邀请赛 A题目 HDU 5236(dp)

先求出没有ctrl+s的时候构造长度为i的期望f[i] 。然后枚举保存的次数,求出最小即可。

#include<cstdio>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;
const int mmax = 100010;
const double inf = 1e20;
double f[mmax];
void build(double p)
{
    f[0]=0;
    for(int i=1;i<mmax;i++)
    {
        f[i]=(f[i-1]+1)/(1.0-p);
    }
}
int main()
{
    int t,ca=0;
    scanf("%d",&t);
    while(t--)
    {
        int n,x;
        double p;
        scanf("%d %lf %d",&n,&p,&x);
        build(p);
        double ans=inf;
        for(int i=0;i<n;i++)
        {
            int k=n/(i+1);
            double tmp=f[k+1]*(n%(i+1))+f[k]*(i+1-n%(i+1));
            tmp+=1.0*(i+1)*x;
            ans=min(ans,tmp);
        }
        printf("Case #%d: %.6lf\n",++ca,ans);
    }
    return 0;
}
时间: 2024-08-29 08:07:10

上海邀请赛 A题目 HDU 5236(dp)的相关文章

上海邀请赛之热身赛2_2013成都邀请赛

先写总结. 感觉这次跟scf和sjc组队有种瞬间碉堡了的感觉,虽然是临时组建的队伍凑齐准备去上海参加邀请赛,从这次比赛磨练配合. 今天比赛难度比前天那次的难度低,感觉更适合我们来练习. 话说好像比赛提早了5分钟,我们三个人都不知道,五分钟后一看A题学长已经A了,一想肯定特水...我就没看题,sjc和scf两个看了题,scf就开始敲了,我刚开始负责翻译题,虽然我英语是个渣渣...没办法,没翻译他们几乎做不出题...我就没做题,翻译了B和G.scf敲了貌似好久才完成(赛后重做,特水,基本3分钟就可以

[POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线

Description Byteman, one of the most deserving employee of The Goldmine of Byteland, is about to retire by the end of the year. The Goldmine management would like to reward him in acknowledgment of his conscientious work. As a reward Byteman may rece

hdu 5389 dp类似背包

http://acm.hdu.edu.cn/showproblem.php?pid=5389 Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft. Stilwell is enjoying the first chapter of this

2015上海邀请赛

这次上海邀请赛差一点就能拿到牌子了,好可惜..... Game回来写了下,刚开始把重链写成了最大权子树,无限WA,然后一直在调..... 发现我一旦提交上去错了就始终在找程序BUG,从来没想过是不是思路哪里错掉了....其实这种交上去WA之后应该先去找思路上的错误,而不是怀疑题目有陷阱什么的... #include<stdio.h> #include<string.h> #include<vector> #include<list> #include<

HDU 4832(DP+计数问题)

HDU 4832 Chess 思路:把行列的情况分别dp求出来,然后枚举行用几行,竖用几行,然后相乘累加起来就是答案 代码: #include <stdio.h> #include <string.h> #include <iostream> using namespace std; typedef long long ll; const ll MOD = 9999991; const int N = 1005; int t, n, m, k, x, y; ll dp1

西安邀请赛J题 状态压缩DP

Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.Cacti是通过 snmpget来获取数据,使用 RRDtool绘画图形,而且你完全可以不需要了解RRDtool复杂的参数.它提供了非常强大的数据和用户管理功能,可以指定每一个用户能查看树状结构.host以及任何一张图,还可以与LDAP结合进行用户验证,同时也能自己增加模板,功能非常强大完善.界面友好.软件 Cacti 的发展是基于让 RRDTool 使用者更方便使用该软件,除了基本的 Snmp 流量

hdu 3944 dp?

DP? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 128000/128000 K (Java/Others)Total Submission(s): 1804    Accepted Submission(s): 595 Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0,1,2,-a

A Computer Graphics Problem 4176 2013上海邀请赛

A Computer Graphics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 968    Accepted Submission(s): 688 Problem Description In this problem we talk about the study of Computer Graphics.

hdu 1025 dp 最长上升子序列

1 //Accepted 4372 KB 140 ms 2 //dp 最长上升子序列 nlogn 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 using namespace std; 7 const int imax_n = 500005; 8 int dp[imax_n]; 9 int d[imax_n]; 10 int a[imax_n]; 11 int n; 12 int len