hdu4803Poor Warehouse Keeper

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4803

题意:有两个按钮,两个显示屏,一个显示数量,一个显示总价(浮点数但只显示整数位)。A按钮按一下数量会增加1同时总价会增加一个单价,B按钮按一下总价会增加1。给定x,y求从1,1的初始状态最少按多少次能达到x,y。

分析:仔细分析一下我们会发现按A键单价不变,按B键单价上升,而最后的单价最大是(y+1-eps)/x,A键按的次数肯定是x-1次的,那么就是要求B键按得最少,我们要的是使单价从1快速达到要求,很容易想到当x小的时候我们应当尽可能的按B键,这样就能最快得达到要求并且使得按键次数最少啦。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=100010;
const int mod=100000000;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=2000000010;
const ll MAX=1ll<<55;
const double pi=acos(-1.0);
const double eps=1e-5;
typedef double db;
typedef unsigned long long ull;
int main()
{
    int i,n,m,w,ans;
    db P,last;
    while (scanf("%d%d", &n, &m)!=EOF) {
        if (n>m) printf("-1\n");
        else {
            ans=n-1;last=1.0;
            P=1.0*(m+1-eps)/n;
            for (i=1;i<=n;i++) {
                w=(int)(i*P-last);
                ans+=w;last+=w;
                last+=last/i;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值