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的更多相关文章
随机推荐
- 帮助理解委托、匿名委托、Lambda表达式还有事件
写了一个小程序,能够很好的认识到这三个的用法 namespace Lambda { /// <summary> /// 实现根据指定运算形式 输出结果 /// </summary&g ...
- 最小生成树问题---Prim算法与Kruskal算法实现(MATLAB语言实现)
2015-12-17晚,复习,甚是无聊,阅<复杂网络算法与应用>一书,得知最小生成树问题(Minimum spanning tree)问题.记之. 何为树:连通且不含圈的图称为树. 图T= ...
- linux系统安装jdk
OpenJdk8安装: sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openj ...
- Scala implicit
Scala implicit implicit基本含义 在Scala中有一个关键字是implicit, 之前一直不知道这个货是干什么的,今天整理了一下. 我们先来看一个例子: def display( ...
- C# 字符串处理
1.比较字符串 String 类提供了一系列的方法用于字符串的比较,如CompareTo 和 Equals方法等. ① CompareTo : 如果参数的值与此实例相等,则返回0:如果此实例大于参数 ...
- Android shell 下 busybox,clear,tcpdump、、众多命令的移植
http://my.oschina.net/mopidick/blog/167372 作为一名Android开发者,经常需要进入Android 的shell终端运行一些命令.但是我们发现Android ...
- 高性能JavaScript(您值得一看)
众所周知浏览器是使用单进程处理UI更新和JavaScript运行等多个任务的,而同一时间只能有一个任务被执行,如此说来,JavaScript运行了多长时间就意味着用户得等待浏览器响应需要花多久时间. ...
- Untiy3D - 窗口界面1
记录Untiy3D学习中的英语单词 一.Project窗口下的英语单词 First Day Folder : 文件夹 C# Script : C#脚本 JavaScript:JS脚本 Editor T ...
- 【原】redux异步操作学习笔记
摘要: 发觉在学习react的生态链中,react+react-router+webpack+es6+fetch等等这些都基本搞懂的差不多了,可以应用到实战当中,唯独这个redux还不能,学习redu ...
- .net4.0及Silverlight_Tools for vs2008sp1安装失败解决办法
安装.net framework 4.0失败,出现HRESULT 0xc8000222错误代码 1.开始-运行-输入cmd,运行命令 net stop WuAuServ 2.开始-运行-输入 ...