首页 > 其他 > 详细

hdu-4803 Poor Warehouse Keeper

时间:2020-01-12 21:25:43      阅读:92      评论:0      收藏:0      [点我收藏+]

题目连接 :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\n");
            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\n", ans);
    }


    return 0;
 }

hdu-4803 Poor Warehouse Keeper

原文:https://www.cnblogs.com/hulian425/p/12184431.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!