hdu 4803B
来源:互联网 发布:东北师范大学网络教育 编辑:程序博客网 时间:2024/06/07 16:15
B - Poor Warehouse Keeper
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?
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.
1 13 89 31
0511
For the second test case, one way to achieve is:(1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)
题解:把y分成x份(给定的目标数),然后在对每一份进行加y的操作,不然y太多了肯定会超时。
代码:#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<queue>#include<deque>using namespace std;typedef long long ll;double x, y, a, b, price;int main() { int Count, sum; while(scanf("%lf%lf", &x, &y) != EOF) { Count = 0; sum = 0; if(x > y) { printf("-1\n"); continue; } Count = (int)x- 1; price = (y+0.999999)/x; b = 1; for(int i = 1; i <=(int)x; i++) { sum = (int)(i*price-b); Count += sum; b += sum; b = b*(i+1)/i; } printf("%d\n", Count); } return 0;}
阅读全文
0 0
- hdu 4803B
- HDU 3652 B-number
- HDU 2033 A+B
- HDU 2034 A-B
- hdu 1412 {A} + {B}
- HDU 1096 A+B
- HDU A^B
- HDU 1412 {A}+{B}
- hdu 1228A+B
- HDU 1412 ( {A} + {B} )
- HDU 1228 ( A + B )
- hdu 1288 A + B
- hdu 1228 A + B
- HDU 1229 A + B
- HDU 1412 {A}+{B}
- hdu A/B
- hdu A/B
- hdu 1228 A + B
- Vs2013打开项目时,一直处理等待状态,并显示“Microsoft Visual Studio正忙”的提示窗,处理方法
- 三种方法实现斐波那契数列
- 神经网络使用心得
- poj 1988 Cube Stacking(加权并查集 )
- Python编程:从入门到实践的动手试一试答案(第八章)
- hdu 4803B
- 矩阵链相乘--动态规划
- 2017
- [luogu3258][JLOI2014]松鼠的新家
- AOSP 安卓7.1 ubuntu17.04编译问题
- n位2进制输出 我就是不用递归你咬我啊
- Adobe Lightroom Classic CC 2018 Mac 官方版下载
- bzoj 4565 字符合并 DP 解题报告
- Linux 查找Java和Oracle运行进程,kill掉