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. ssh-keygen的使用方法(无密码访问)

    一.概述 1.就是为了让两个linux机器之间使用ssh不需要用户名和密码.采用了数字签名RSA或者DSA来完成这个操作 2.模型分析 假设 A (192.168.20.59)为客户机器,B(192. ...

  2. Unreal Engine 4(虚幻UE4)GameplayAbilities 插件入门教程(五)技能属性集(AttributeSet)

    如果没有完成前面的教程,请前往学习.先上一段理论介绍(源于https://wiki.unrealengine.com/GameplayAbilities_and_You#GameplayTasks): ...

  3. js之ActiveX控件使用说明 new ActiveXObject()

    什么是 ActiveX 控件? ActiveX 控件广泛用于 Internet.它们可以通过提供视频.动画内容等来增加浏览的乐趣.不过,这些程序可能出问题或者向您提供不需要的内容.在某些情况下,这些程 ...

  4. Dubbo与Zookeeper、Spring整合使用

    Dubbo与Zookeeper.Spring整合使用 Dubbo采用全spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spri ...

  5. 通过优化在UE4中实现良好性能和高质量视觉效果

    转自:http://gad.qq.com/program/translateview/7160166 译者:赵菁菁(轩语轩缘)  审校:李笑达(DDBC4747) 对于任何追求UE4性能最佳.同时又想 ...

  6. oracle 11g RAC 的一些基本概念(三)

    Grid Infrastructure共享组件   Grid Infrastructure使用两种类型的共享设备来管理集群资源和节点:OCR(Oracle Cluster Registry)和表决磁盘 ...

  7. pig和mysql脚本对比

    测试数据位于:/home/hadoop/luogankun/workspace/sync_data/pig dept和emp表来源自oracle数据库自带的表 dept.txt ACCOUNTING ...

  8. RHEL6.x查看网卡槽位对应设备文件及路径

    先查看网卡mac地址,由于我的服务器做了mac地址绑定,所以会有相同的hwaddr地址,请忽略. [root@node-0a0a05d3- net]# ifconfig eth0 | grep HWa ...

  9. CSS3基础

    内容: 1.圆角 border-radius 2.阴影 text-shadow.box-shadow 3.渐变 linear.radial 4.rgba rgb+alpha opacity 5.tra ...

  10. python中的模块及包及软件目录结构规范

    知识内容: 1.模块的定义与分类 2.模块的导入 3.模块与包 4.不同目录下的模块调用 一.模块的定义与分类 1.什么是模块 模块就是实现了某个功能的代码集合,模块是由一大堆代码构成的 类似于函数式 ...