Poor Warehouse Keeper

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

Jenny is a warehouse keeper. He writes down the entry records everyday. The record is shown on a screen, as follow:

There are only two buttons on the screen. Pressing the button in the first line once increases the number on the first line by 1. The cost per unit remains untouched. For the screen above, after the button in the first line is pressed, the screen will be:

The exact total price is 7.5, but on the screen, only the integral part 7 is shown.
Pressing the button in the second line once increases the number on the second line by 1. The number in the first line remains untouched. For the screen above, after the button in the second line is pressed, the screen will be:

Remember the exact total price is 8.5, but on the screen, only the integral part 8 is shown. 
A new record will be like the following:

At that moment, the total price is exact 1.0.
Jenny expects a final screen in form of:

Where x and y are previously given.
What’s the minimal number of pressing of buttons Jenny needs to achieve his goal?

 
Input
There are several (about 50, 000) test cases, please process till EOF.
Each test case contains one line with two integers x(1 <= x <= 10) and y(1 <= y <= 109) separated by a single space - the expected number shown on the screen in the end.
 
Output
For each test case, print the minimal number of pressing of the buttons, or “-1”(without quotes) if there’s no way to achieve his goal.
 
Sample Input
1 1
3 8
9 31
 
Sample Output
0
5
11
Hint

For the second test case, one way to achieve is:
(1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)

 
Source

直接贪心模拟即可

 #include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#define maxn 200005
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std; int main(){
double a,b,x,y,tmp;
while(cin>>x>>y){
a=,b=;
int step=;
if(x>y){
cout<<-<<endl;
}
else{
double danjia=(y+0.9999)/x;
double danjia_double=danjia;
int tmp;
while(a<x&&b<y){
if(danjia_double-b->=0.000001){
tmp=int(danjia_double-b);
step+=tmp;
b+=tmp; }
else{
step++;
b+=b/a;
a++;
danjia_double=a*danjia;
}
// cout<<a<<" "<<b<<" "<<danjia_double<<" "<<step<<endl;
}
if((danjia_double-b+0.00001)>){
step+=danjia_double-b;
}
cout<<step<<endl;
}
}
}

Poor Warehouse Keeper的更多相关文章

  1. hdu 4803 Poor Warehouse Keeper(贪心+数学)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26005267 题目链接:hdu 4803 P ...

  2. HDU 4803 Poor Warehouse Keeper (贪心+避开精度)

    555555,能避开精度还是避开精度吧,,,,我们是弱菜.. Poor Warehouse Keeper Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  3. 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...

  4. HDU 4803 Poor Warehouse Keeper

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4803 解题报告:有一个记录器,一共有两个按钮,还有两行屏幕显示,第一行的屏幕显示的是数目,第二行的屏幕 ...

  5. 【贪心】hdu4803 Poor Warehouse Keeper

    题意:一开始有1个物品,总价是1.你的一次操作可以要么使得物品数量+1,总价加上当前物品的单价.要么可以使得总价+1,物品数量不变.问你最少要几次操作从初始状态到达有x个物品,总价是y的状态.这里的y ...

  6. HDU 4803 Poor Warehouse Keeper(贪心)

    题目链接 题意 :屏幕可以显示两个值,一个是数量x,一个是总价y.有两种操作,一种是加一次总价,变成x,1+y:一种是加一个数量,这要的话总价也会相应加上一个的价钱,变成x+1,y+y/x.总价显示的 ...

  7. HDU - 4803 - Poor Warehouse Keeper (思维)

    题意: 给出x,y两个值分别代表x个物品,总价为y 有两种变化: 1.使总价+1,数量不变 2.数量+1,总价跟着变化 (y = y + y / x) 思路: 给出目标x,y,计算最少变化次使数量变化 ...

  8. ZOJ 2601 Warehouse Keeper

    Warehouse Keeper Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origin ...

  9. HDU4803_Poor Warehouse Keeper

    题目很有意思,我想说其实我在比赛的时候就看过了一下这个题目,今天才这么快搞出来吧. 其实总共按上键的次数不会超过10个,我们可以每次假设相隔按两次上键之间按了xi次下键,由于上键的次数是确定的,所以最 ...

随机推荐

  1. 开发框架-开发组合:LAMP(Web应用软件组合)

    ylbtech-开发框架-开发组合:LAMP(Web应用软件组合) LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写. 1.返回顶部 1. 中文名:lamp 外文名:lam ...

  2. [UE4]C++ getter and setter

    问:以前面向对象没学好.... 最近老是在想,既然要设为private为什么还要写个setter来改变它的值呢? 为什么不直接把它直接设成public倒省事? 呵呵,谢啦 答:用setter来改变数据 ...

  3. http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728.html

    http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728.html

  4. javascript创建对象之构造函数模式(二)

    对上一章节的工厂模式进行代码重写 function Human(name, sex) { this.name = name; this.sex = sex; this.say = function ( ...

  5. Java与C++语法的区别

    1. 注释可以在Java程序中起到文档标记的作用 类文档标记: 1)@version 2)@author 3)@param 4)@return 5)@exception 2. Java的字符占两个字节 ...

  6. 用docker搭建php+nginx+laravel的开发环境

    制作镜像 由于官方php:7.2.2-fpm-alpine3.7 镜像不含composer,而单独做一个composer镜像又会依赖php镜像,所以应该在php镜像中添加composer.Docker ...

  7. php while循环控制实例讲解

    while循环是PHP中最简单的循环,其基本格式为: while (expr){ statement } 或者 while (expr): statement endwhile; 该语法表示,只要ex ...

  8. C# window Service实现调用有UI的应用程序(关于win xp以后的window系统)

    我开发的系统中有一接口程序(这里就称Task,是一个C#的Console Application)经常无故的死掉,导致第二天的数据不能正常解析,所以,我写了一个window service去监视Tas ...

  9. mysql 分片

    MySQL Fabric(分片)  是一个用于管理 MySQL 服务器群的可扩展框架.该框架实现了两个特性 — 高可用性 (HA ) 以及使用数据分片的横向扩展.这两个特性既可以单独使用,也可以结合使 ...

  10. 数据库入门4 结构化查询语言SQL

    知识内容: 1.了解SQL 2.库.表操作及索引 3.select语句及insert语句 4.update语句与delete语句 5.SQL常用函数 6.多表连接及组合查询 7.视图操作及数据控制 参 ...