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的更多相关文章
随机推荐
- ( 译、持续更新 ) JavaScript 上分小技巧(一)
感谢好友破狼提供的这篇好文章,也感谢写这些知识点的作者们和将他们整理到一起的作者.这是github上的一篇文章,在这里本兽也就只做翻译,由于本兽英语水平和编程能力都不咋地,如有不好的地方也请多理解体谅 ...
- CF 214B Hometask(想法题)
题目链接: 传送门 Hometask Time Limit: 2 seconds Memory Limit: 256 megabytes Description Furik loves mat ...
- How to overcome “datetime.datetime not JSON serializable” in python?
json.dumps(datetime.now) 意思是datetime.now不可json序列化,解决办法是转化成str或者加一个参数 cls=xxx 详细见: http://stackoverfl ...
- 【Phylab2.0】Alpha版本测试报告
测试报告集 点击链接
- @interface NSFileManager : NSObject
@interface NSFileManager : NSObject NSFileManager操作: 1.文件夹创建删除 2.文件创建删除 3.清除数据缓存 以上办法都在这里:https://de ...
- javascript应用之如何判断一个数为素数
判断是否为素数? 质数(prime number)又称素数,有无限个.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数的数称为质数. 合数,数学用语,英文名为Composite numb ...
- css3之2D转换
css3---2D转换 css3中出现了许多新的特性,其中2D转换我觉的非常有意思,通过她,我们能够对元素进行移动.缩放.转动.拉长或者拉伸,所以希望在这里和大家分享一下. 这里,我将会介绍到以下转换 ...
- Objective-C学习笔记类目、协议
不是所有的方法都可以被覆盖的!比如:intValue就不能被覆盖!! 原因正在查找中! 别人的电脑上却可以! 类目.h件 #import <Foundation/Foundation.h> ...
- 简单说说Tk和Tcl
开园第一个博客,简单说说Tk和Tcl. 我接触Tk和Tcl是在学习Python Tkinter时候,创建Tk对象,下面言归正传: Tcl:工具命令语言,英文全称为Tool Command Langua ...
- Oracle开发常用函数与存储过程
create or replace function Fuc_Get_AuthorName(RecID_In in varchar2, AdmID_In in varchar2) return var ...