hdu 4803 (想法题 卡精度)
来源:互联网 发布:cs1.6参数优化 编辑:程序博客网 时间:2024/05/27 06:56
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4803
Poor Warehouse Keeper
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1493 Accepted Submission(s): 428
Problem Description
Jenny is a warehouse keeper. He writes down the entry records everyday. The record is shown on a screen, as follow:
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?
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
There are several (about 50, 000) test cases, please process till EOF.
Each test case contains one line with two integers x(1 <= x <= 10) and y(1 <= y <= 109) separated by a single space - the expected number shown on the screen in the end.
Each test case contains one line with two integers x(1 <= x <= 10) and y(1 <= y <= 109) separated by a single space - the expected number shown on the screen in the end.
Output
For each test case, print the minimal number of pressing of the buttons, or “-1”(without quotes) if there’s no way to achieve his goal.
Sample Input
1 13 89 31
Sample Output
0511HintFor the second test case, one way to achieve is:(1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)
把上面那个按钮 称为按钮1;
下面那个按钮 称为按钮2;
如果按下按钮2,会使总价加1,数量不变,单价=(总价+1)/数量;
现在问至少多少步可以使得 按钮1数字为x, 按钮2数字为y;
思路:(1)由题意容易知道至少 需要 x-1步(按上面的按钮);
(2)最后可以转化为单价的问题,给定x,y后,不论按哪个按钮,单价只会呈现上身趋势,并且达到最大,那么就由最大的单价倒着推出每两次按下按钮1之间按下按钮2次数的最大值(贪心)
#include <iostream>#include <string.h>#include <string>#include <cstdio>#include <cmath>#include <cstdio>#include <algorithm>typedef long long ll;const double eps=1e-5;using namespace std;int main(){ double x,y; while(scanf("%lf%lf",&x,&y)!=EOF) { if(x>y) { cout<<-1<<endl; continue; } double s=(y+1-eps)/x; int cnt=(int)x-1; double tmp=1; for(int i=1;i<=(int)x;i++) { int t=(int)(s*i-tmp); tmp+=t; cnt+=t; tmp=tmp/i*(i+1); } printf("%d\n",cnt); } return 0;}
0 0
- hdu 4803 (想法题 卡精度)
- hdu 4811(想法题)
- hdu 5744(想法题)
- Poor Warehouse Keeper hdu 4803(思维,卡精度)
- HDU-#5003 Osu!(精度题)
- hdu 5358 First One(想法题)
- hdu 5178想法题
- HDU-4811 Ball 想法题
- Frog - HDU 5037 想法题
- hdu 4104 Discount (想法题)
- hdu 1789 小想法题
- hdu 4970小想法题
- hdu 6050 Function 想法题
- HDU 6105 Gameia [想法题]
- HDU-4803-贪心+卡精度(挺难的)
- HDU 2410 Barbara Bennett's Wild Numbers (想法题)
- hdu 5386 Cover(暴力求解+想法题)
- hdu(5400)——Arithmetic Sequence(想法题)
- Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅
- 酵素哪个牌子好 如何挑选天然水果酵素
- How to set up linux watchdog daemon with Intel 6300esb
- 数值分析类智力题(IT产品类笔面试题型真题分析)
- Python 迭代器 & __iter__方法
- hdu 4803 (想法题 卡精度)
- java基础问题
- matlab提取视频流与图片成视频
- 项目中用到的logback列子
- java string转float类型,并且保留对应位数
- Android离线配置方法
- zendframework搭建为什么cmd窗口是这样的,"php.exe"' 不是内部或外部命令,也不是可运行的程序
- PHP,Mysql-根据一个给定经纬度的点,进行附近地点查询–合理利用算法
- 移动开发平台性能比较