B - Poor Warehouse Keeper

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2014-10-09)

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 <= 10 9) 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
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define M(a,b) memset(a,b,sizeof(a))
#include<map>
#include<stdlib.h>
#define eps 1e-5
using namespace std; double x,y; int main()
{
while(scanf("%lf%lf",&x,&y)==)
{
double lim = (y+)/x-eps;
double pri = ;
int num = ;
int tim = ;
double all = ;
if(x>y) {puts("-1"); continue;}
while()
{
if(all-y>||fabs(all-y)<eps)
break;
//cout<<lim<<endl;
int tmp = (int)((lim - pri)/(1.0/num));
pri+=tmp*(1.0/num);
//cout<<pri<<' '<<tmp<<endl;
tim+=tmp;
all+= tmp;
if(tmp==)
{
int tm = (int)(1.0/(lim-pri)-num)+;
if(tm>(y+-eps-all)/pri)
tm = (int)((y+-eps-all)/pri);
num+=tm;
tim+=tm;
all+=pri*tm;
}
// cout<<tim<<endl;
//cout<<all<<endl;
}
printf("%d\n",tim);
}
return ;
}

2013nanjignB的更多相关文章

随机推荐

  1. JUnit报错:java.lang.ClassNotFoundException:

    只要把Java--------compiler-------building-------Buil path problems ------- incomplete build path 和 Circ ...

  2. django中migration文件是干啥的

    昨天很蠢的问leader git push的时候会不会把本地的数据库文件上传上去,意思是django中那些migration文件修改之后会不会上传. 然后得知不会,因为所有的数据库都存在本机的mysq ...

  3. How to overcome “datetime.datetime not JSON serializable” in python?

    json.dumps(datetime.now) 意思是datetime.now不可json序列化,解决办法是转化成str或者加一个参数 cls=xxx 详细见: http://stackoverfl ...

  4. soapUI使用-DataSource获取oracle库中的参数

    soapUI使用-DataSource获取oracle库中的参数 下载mysql和oracle驱动包:http://pan.baidu.com/s/1i3sy1MH 放在Program Files\S ...

  5. “K米” 软件产品评测

    第一部分 调研,评测 评测: 第一次上手体验:KTV相信很多人都有去过,大部分包厢只有哦一个点歌台,相信很多人都会烦恼于一堆人挤在小小的点歌台前点歌的样子,还有些人不太好意思跑到点歌台点歌,常常是碰到 ...

  6. bookstrap必备的基础知识

  7. VRRP协议详解

    今天做了lvs的负载均衡的实验,竟然成功了,出乎我意料......哈哈哈哈 http://blog.csdn.net/fanlu319/article/details/7013258

  8. Ubuntu修改mysql默认编码的方法

    ubuntu使用apt-get安装mysql后,server的默认编码是latin1,下面把server的编码修改成utf8. 编码相关信息: 1 2 3 4 5 6 7 8 9 10 11 12 1 ...

  9. [转载]将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,解决办法

    eclipse 代码中文注释乱码 求解决 将别人的项目或JAVA文件导入到自己的Eclipse中时,常常会出现JAVA文件的中文注释变成乱码的情况,主要原因就是别人的IDE编码格式和自己的Eclips ...

  10. HTML学习笔记——锚链接、pre标签、实体

    1>锚链接 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...