题目链接

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

Problem Description
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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5901 5899 5898 5897 5896 
 
 
 
题意:有一种显示器带有两个按钮,显示器上有两个数 ,显示器只能显示整数,小数部分不显示(实际上是小数,只是小数部分不显示出来),显示器上的的初始数为x=1.0  y=1.0  ,如果按上面一个按钮,第一个数x加一,y变为y=(y/x)*(x+1),  如果按下面一个按钮,x不变,y加一,现在输入两个数,求最小的步数使得1 1 变到这两个数;
 
思路: (1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)  分析这个样例,设输入的两个数为x  y  s1=1.0  s2=1.0 我们可以先增加s2值,尽可能的增加s2值,但要保证增加后的s2值满足s2/s1<=y/x  为什么呢? 这样做是为了保证增加s1 的时候不会让s2 大于y  然后增加一次s1,再回到上面的过程增加s2 ...... s1小于10 所以复杂度很低的。 最后要注意一下精度,因为显示器不显示小数部分,所以可以把y加上0.99999999 ;
 
代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <queue>
#include <vector>
using namespace std;
const double esp=1e-; int main()
{
double x,y,s1,s2;
while(scanf("%lf%lf",&x,&y)!=EOF)
{
y+=0.9999999;
long long sum=;
if(x>y) { puts("-1"); continue; }
s1=1.0; s2=1.0;
while()
{ if(s1-x+esp>=esp&&s1-(x+)<esp) break;
long long t=(long long)(y*s1/x-s2);
sum+=t;
s2=s2+t; s2=s2*(s1+)/s1;
s1=s1+;
sum++;
if(s1>=x&&s1-(x+)<esp) break;
}
sum+=(long long)(y-s2);
printf("%lld\n",sum);
}
return ;
}

2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)的更多相关文章

  1. 2013ACM/ICPC亚洲区南京站现场赛——题目重现

    GPA http://acm.hdu.edu.cn/showproblem.php?pid=4802 签到题,输入两个表,注意细心点就行了. #include<cstdio> #inclu ...

  2. 2013ACM/ICPC亚洲区南京站现场赛-HDU4809(树形DP)

    为了这个题解第一次写东西..(我只是来膜拜爱看touhou的出题人的).. 首先以为对称性质..我们求出露琪诺的魔法值的期望就可以了..之后乘以3就是答案..(话说她那么笨..能算出来么..⑨⑨⑨⑨⑨ ...

  3. hdu4811-Ball(2013ACM/ICPC亚洲区南京站现场赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4811 题目描述: Problem Description Jenny likes balls. He ...

  4. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  5. 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)

    http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...

  6. 2013ACM-ICPC亚洲区南京站现场赛G题

    题目大意:一个n维的系统中随机选一个向量(X1,X2,X3,...,Xn),其中0<=Xi<=R,且X1^2+X2^2+X3^2+……+Xn^2 <= R^2. 现在给定n,R.求X ...

  7. 2014ACM/ICPC亚洲区西安站现场赛 F color(二项式反演)

    题意:小球排成一排,从m种颜色中选取k种颜色给n个球上色,要求相邻的球的颜色不同,求可行的方案数,答案模1e9+7.T组数据,1<= n, m <= 1e9, 1 <= k < ...

  8. HDU 6227.Rabbits-规律 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    Rabbits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  9. HDU 6225.Little Boxes-大数加法 (2017ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学))

    整理代码... Little Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/O ...

随机推荐

  1. MVVM架构~knockoutjs系列之为validation.js扩展minLength和maxLength

    返回目录 为什么要对minLength和maxLength这两个方法进行扩展呢,是因为这样一个需求,在用户注册时,可以由用户自己决定他们输入的字符,中文,英文,数字均可,这样做了之后,使用户的体验更好 ...

  2. 知方可补不足~用CDC功能来对数据库变更进行捕捉

    回到目录 如果我们希望监视一个数据表的变化,在sql2008之前的版本里,在数据库端可能想到的只有触发器,或者在程序端通过监视自己的insert,update,delete来实现相应的功能,这种实现无 ...

  3. ajax图片上传及FastDFS入门案例.

    今天来开始写图片上传的功能, 现在的图片上传都讲求 上传完成后立刻回显且页面不刷新, 这里到底是怎么做的呢? 当然是借助于ajax了, 但是ajax又不能提交表单, 这里我们还要借助一个插件: jqu ...

  4. Atitit.加密算法ati Aes的框架设计v2.2

    Atitit.加密算法ati Aes的框架设计v2.2 版本进化1 V2.2   add def decode key api1 v1版本1 Aes的历史2 Atitit.加密算法 des  aes  ...

  5. Atitit jsr规范有多少个  407个。Jsr规范大全

    Atitit jsr规范有多少个  407个.Jsr规范大全 1.1. JCP维护职能是发展和更新.1 1.2. Java技术规范.参考实现(RI).技术兼容包(TCK)1 1.3. JCP维护的规范 ...

  6. Atitit 图像处理 灰度图片 灰度化的原理与实现

    Atitit 图像处理 灰度图片 灰度化的原理与实现 24位彩色图与8位灰度图 首先要先介绍一下24位彩色图像,在一个24位彩色图像中,每个像素由三个字节表示,通常表示为RGB.通常,许多24位彩色图 ...

  7. Atitit 热更新资源管理器 自动更新管理器 功能设计

    Atitit 热更新资源管理器 自动更新管理器 功能设计 · 多线程并行下载支持 · 两层进度统计信息:文件级以及字节级 · Zip压缩文件支持 · 断点续传 · 详细的错误报告 · 文件下载失败重试 ...

  8. 使用 flow.ci 实现 Android 自动化测试与持续集成

    在上篇文章--如何实现 Android 应用的持续部署中,我们使用的是 flow.ci + Github + fir.im 实现 Android 应用的持续部署.对于 Android 开发者,他们可能 ...

  9. 关于WPF中RichTextBox失去焦点后如何保持高亮显示所选择的内容

    其实很简单,只要将容器控件中的附加属性FocusManager.IsFocusScope设为True就可以了 下面是个简单的用例: <Window x:Class="WpfApplic ...

  10. ngOptions

    ngOptions select as select as label for value in array <select ng-model="myColor" ng-op ...