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的更多相关文章
随机推荐
- C#的Invoke和BeginInvoke
在Invoke或者BeginInvoke的使用中无一例外地使用了委托Delegate,至于委托的本质请参考我的另一随笔:对.net事件的看法. 一.为什么Control类提供了Invoke和Begin ...
- Guava 集合框架
在本系列中我们首先来学习一些Guava的集合框架,也就是这个package:com.google.common.collect 在这个包下面有一些通用的集合接口和一些相关的类. 集合类型: BiM ...
- EF 知识点
EntityFrameWorak知识点记录 发展史 EF1.0时,只支持Database First,数据库优先.必须将设计器指向一个现有的数据库. EF4时,支持Model First,模型优先.可 ...
- HDU 2544 单源最短路
题目链接: 传送门 最短路 Time Limit: 1000MS Memory Limit: 65536K 题目描述 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是 ...
- linux下git的简单运用
linux下git的简单运用 windows下也有git,是git公司出的bash,基本上模拟了linux下命令行.许多常用的命令和linux下操作一样.也就是说,windows下的git命令操作和l ...
- w3m常用快捷键
H 显示帮助 q 退出,会有提示的 j,k,l,h 移动光标 J/K 向下/向上滚屏 T 打开一个新标签页 Esc-t 打开所有标签页,供你选择,使用jk来上下移动 U ...
- WinForm------点击Control弹出MessageBox
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { //弹 ...
- 《Struts2.x权威指南》学习笔记2
在学习了第二章后,我想要将struts分类,修改一下struts.xml的默认读取路径如下图. 在IntelliJ中,resources是struts的默认路径 修改路径,需要在web.xml中添加s ...
- JDK的安装和配置
JDK8 是JDK的最新版本,加入了很多新特性,如果我们要使用,需要下载安装: JDK8在windows xp下安装有点问题,所以在WIN7下安装 WIN7操作系统有32位和64位,分别要下载对应的J ...
- IOS: 账号,证书 好文整理
公钥.私钥.数字证书的概念 http://blog.csdn.net/turui/article/details/2048582 iOS Provisioning Profile(Certificat ...