zoukankan      html  css  js  c++  java
  • hdu-4803 Poor Warehouse Keeper

    题目连接 :http://acm.hdu.edu.cn/showproblem.php?pid=4803

    思路

    第一种操作数量加1,第二种操作单价加y/x,所以第一种操作的数量是肯定不变的,只能操作x-1次,所以只需要在每次进行操作一之前,先进行操作2,让其到达最大单价。那么如何得到最大单价呢,易得y1 = (y + 1 -eps)*i/x;然后重复进行此操作,相当于减而治之。

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    const double eps=1e-5;
    using namespace std;
    int main()
    {
        double x,y;
        while(~scanf("%lf %lf",&x,&y))
        {
            if(y<x)
            {
                printf("-1
    ");
                continue;
            }
            double y1 = 1;
            int ans = 0;
            for (double i = 1; i < x; i += 1)
            {
                double now = (y + 1 - eps)*i /x;
                int add  = floor(now - y1);
                ans += add;
                y1 += add;
                ans++;
                y1 += y1/i;
            }
            // double now = (y + 1 - eps)*i /x;
            ans += floor(y + 1 - eps - y1);
            printf("%d
    ", ans);
        }
    
    
        return 0;
     }
  • 相关阅读:
    Apache POI 示例
    使用wsimport生成webservice客户端代码
    监听器
    @WebFilter注解
    事务
    k8s的deployment应用
    k8s 组件架构
    使用kubeadm安装kubernetes1.12.1
    轻量级批量管理工具pssh
    使用Bind服务配置DNS服务器
  • 原文地址:https://www.cnblogs.com/hulian425/p/12184431.html
Copyright © 2011-2022 走看看