Poor Warehouse Keeper
Poor Warehouse Keeper
http://acm.hdu.edu.cn/showproblem.php?pid=4803
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?
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.
For the second test case, one way to achieve is:
(1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)
直接贪心模拟即可
#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#define maxn 200005
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std; int main(){
double a,b,x,y,tmp;
while(cin>>x>>y){
a=,b=;
int step=;
if(x>y){
cout<<-<<endl;
}
else{
double danjia=(y+0.9999)/x;
double danjia_double=danjia;
int tmp;
while(a<x&&b<y){
if(danjia_double-b->=0.000001){
tmp=int(danjia_double-b);
step+=tmp;
b+=tmp; }
else{
step++;
b+=b/a;
a++;
danjia_double=a*danjia;
}
// cout<<a<<" "<<b<<" "<<danjia_double<<" "<<step<<endl;
}
if((danjia_double-b+0.00001)>){
step+=danjia_double-b;
}
cout<<step<<endl;
}
}
}
Poor Warehouse Keeper的更多相关文章
- hdu 4803 Poor Warehouse Keeper(贪心+数学)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26005267 题目链接:hdu 4803 P ...
- HDU 4803 Poor Warehouse Keeper (贪心+避开精度)
555555,能避开精度还是避开精度吧,,,,我们是弱菜.. Poor Warehouse Keeper Time Limit: 2000/1000 MS (Java/Others) Memor ...
- 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...
- HDU 4803 Poor Warehouse Keeper
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4803 解题报告:有一个记录器,一共有两个按钮,还有两行屏幕显示,第一行的屏幕显示的是数目,第二行的屏幕 ...
- 【贪心】hdu4803 Poor Warehouse Keeper
题意:一开始有1个物品,总价是1.你的一次操作可以要么使得物品数量+1,总价加上当前物品的单价.要么可以使得总价+1,物品数量不变.问你最少要几次操作从初始状态到达有x个物品,总价是y的状态.这里的y ...
- HDU 4803 Poor Warehouse Keeper(贪心)
题目链接 题意 :屏幕可以显示两个值,一个是数量x,一个是总价y.有两种操作,一种是加一次总价,变成x,1+y:一种是加一个数量,这要的话总价也会相应加上一个的价钱,变成x+1,y+y/x.总价显示的 ...
- HDU - 4803 - Poor Warehouse Keeper (思维)
题意: 给出x,y两个值分别代表x个物品,总价为y 有两种变化: 1.使总价+1,数量不变 2.数量+1,总价跟着变化 (y = y + y / x) 思路: 给出目标x,y,计算最少变化次使数量变化 ...
- ZOJ 2601 Warehouse Keeper
Warehouse Keeper Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origin ...
- HDU4803_Poor Warehouse Keeper
题目很有意思,我想说其实我在比赛的时候就看过了一下这个题目,今天才这么快搞出来吧. 其实总共按上键的次数不会超过10个,我们可以每次假设相隔按两次上键之间按了xi次下键,由于上键的次数是确定的,所以最 ...
随机推荐
- 学习笔记之Unit testing/Integration testing/dotnet test and xUnit
source code https://github.com/haotang923/dotnet/tree/master/src Unit testing C# code in .NET Core u ...
- linux查看某个目录下有哪些文件的命令
分别是ll和ls命令 ll /usr/local/lib ls /usr/local/lib
- 基于标准库实现string和wstring的转换
// convert string to wstring std::wstring to_wstring(const std::string& str, const std::locale&a ...
- Spring 基础使用
1 id 和 name 的区别 id:不可重复,不可包含特殊字符 name:可以重复,可以包含特殊字符 2 scope singleton:配置单例模式(默认),在容器启动时创建对象,而且只创建一个 ...
- hbase建表时 ERROR: java.io.IOException: Table Namespace Manager not ready yet, try again later
其实解决不难,是因为时钟不同步,把每个节点切换到root用户下同步时钟就好了,在重启hbase!
- express无中间件的增删改查
index.js const express = require("express");导入express框架 const data = require("./data& ...
- web本质
知识内容: 1.网络协议复习 2.模拟web 3.web本质总结 参考: http://www.cnblogs.com/wupeiqi/articles/5237672.html http://www ...
- 关于 百度 Ueditor (在chrome浏览器) 上传图片时 打开文件夹的延迟问题
在使用 ueditor 开发时, 作为一个web文本编辑器使用时. 当点击上传图片时, 文件夹要延迟好久才能打开. 解决: 针对多图片上传, 将/ueditor/dialogs/image/image ...
- python之匿名函数和递归函数
递归函数 <1>什么是递归函数 通过前面的学习知道一个函数可以调用其他函数. 如果一个函数在内部不调用其它的函数,而是自己本身的话,这个函数就是递归函数. <2>递归函数的作用 ...
- 【Flutter】Flutter 一些常用库
Flutter社区和资源传送门 新: 慕课网<Flutter入门与案例实战> | 中文网<Flutter实战>电子书 字体图标生成 http://fluttericon ...