2013nanjignB
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-10-09)
Description
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
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
Sample Input
3 8
9 31
Sample Output
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的更多相关文章
随机推荐
- jpa注解
http://www.oracle.com/technetwork/cn/middleware/ias/toplink-jpa-annotations-100895-zhs.html#ManyToOn ...
- sublime配置java编译环境
Windows下配置Sublime Text3的Java环境 字数507 阅读2301 评论2 喜欢2 Sublime Text3是一个比较好用的IDE.截图如下: java环境截图 下面就简单介绍下 ...
- ofo走出校园观察:市场定位导致产品错位?
Ofo和摩拜单车虽然同样都是做单车共享,但实际上两者在最初的市场定位是有明显的差异的,因此提供的产品方案也存在巨大的差异. 市场定位不同,导致产品方案的巨大差异 摩拜单车一开始就定位于开放市场,充分的 ...
- Distance Between Points
I need some help. I have to create a function that will calculate the distance between points (x1,y1 ...
- 第5.5次Scrum会议
会议信息 时间:2016.10.25 21:30 时长:0.5h 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 会议内容 鉴于团队推进受阻,原PM 邓 与 原后端 冯 协商后决定之后一段时间 ...
- python列表、元组、字典(四)
列表 如:[11,22,33,44,44].['TangXiaoyue', 'bruce tang'] 每个列表都具备如下功能: class list(object): ""&qu ...
- jQuery知识点总结(第二天)
今天继续从我的笔记上面搬运.我们不产生知识,只是知识的搬运工. 内容过滤选择器: ○ 内容选择过滤器 $("div ...
- DS18B20函数库建立实验
1.主代码: /* 温度传感器 */#include "DS18B20.h"#include"def.h"u16 get_temp (void){ fl ...
- 天行API服务器地址申请
http://www.tianapi.com/ http://www.huceo.com/post/383.html
- setInterval js
$('#start_scan').on('click',function(){ if(timer == undefined){ timer = setInterval(scan,1000) start ...