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的更多相关文章
随机推荐
- HDU 3466 Proud Merchants(01背包问题)
题目链接: 传送门 Proud Merchants Time Limit: 1000MS Memory Limit: 65536K Description Recently, iSea wen ...
- Code::Blocks快捷键操作
编辑器 快捷键 功能 Ctrl+Z 恢复上一次操作 Ctrl+Shift+Z 重复上一次操作 F11 切换头文件/源文件 Ctrl+Shift+C 注释高亮代码 Ctrl+Shift+X 反注释高亮代 ...
- POJ - 1511 Invitation Cards(Dijkstra变形题)
题意: 给定一个有向图,求从源点到其他各点的往返最短路径和.且这个图有一个性质:任何一个环都会经过源点. 图中的节点个数范围:0-100w; 分析: 我们先可以利用Dijkstra算法求解从源点到其余 ...
- JavaScript中的事件对象
JavaScript中的事件对象 JavaScript中的事件对象是非常重要的,恐怕是我们在项目中使用的最多的了.在触发DOM上的某个事件时,会产生一个事件对象event,这个对象中包含这所有与事件有 ...
- asp.net xml 增删改操作
user.xml <?xml version="1.0" encoding="utf-8"?> <user> <person> ...
- 多日期选择jQuery插件 MultiDatesPicker for jQuery UI
Multiple-Dates-Picker-for-jQuery-UI是一个多日期选择的jquery控件. GIT源码: https://github.com/dubrox/Multiple-Da ...
- 20145212 实验五《Java网络编程》
20145212 实验五<Java网络编程> 一.实验内容 1.运行下载的TCP代码,结对进行,一人服务器,一人客户端: 2.利用加解密代码包,编译运行代码,一人加密,一人解密: 3.集成 ...
- Wget命令下载、备份博客
-np http://www.cnblogs.com/memory4young/p/ 参考资料: http://www.cnblogs.com/memory4young/p/wget-backup-b ...
- How to read a scientific paper
How to read a scientific paper Nothing makes you feel stupid quite like reading a scientific journal ...
- ECSHOP MYSQL 公用类库中的autoExecute方法
include/cls_mysql.php 正常操作 例如: $sql = “UPDATE ecs_user SET user = ‘buxuan’ WHERE user_id = ″; $db-&g ...