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次下键,由于上键的次数是确定的,所以最 ...
随机推荐
- [原]System.IO.Path.Combine 路径合并
使用 ILSpy 工具查看了 System.IO.Path 类中的 Combine 方法 对它的功能有点不放心,原方法实现如下: // System.IO.Path /// <summary&g ...
- Web API 源码剖析之默认消息处理程序链之路由分发器(HttpRoutingDispatcher)
Web API 源码剖析之默认消息处理程序链-->路由分发器(HttpRoutingDispatcher) 我们在上一节讲述了默认的DefaultServer(是一个类型为HttpServer的 ...
- 使用php的mysqli扩展库操作mysql数据库
简单介绍mysqli: 1.mysqli(mysql improve mysql扩展库的增强版) mysql扩展库和mysqli扩展库的区别 1.mysqli的稳定性 安全性 和 执行效率有所提高 ...
- Linux内存管理大图(第三稿)
http://bbs.chinaunix.net/thread-2018659-2-1.html 描述讨论在http://bbs.chinaunix.net/thread-3760371-1-1.ht ...
- NHibernate.Cfg.HibernateConfigException
在用NHibernate 框架做web 项目时,当项目被成功编译后,按F5 启动调试时,一开始就出现这个错误,刚开始就很郁闷,到底出在哪里?连自己都 不知道,在网上搜来搜去,找了很多的资料终于弄明白了 ...
- python高亮显示输出
知识内容: 1.高亮输出语法 2.高亮输出实例 前言: 在做购物车这道题时遇到了高亮显示输出某些内容的需求,于是就学了一下这方面的知识,以下是python高亮显示输出的使用方法: 购物车链接: ht ...
- python对象转字典
1.基础实现 class TestDict: name = "wyb" age = " def __init__(self): self.gender = 'male' ...
- selenium+python自动化87-Chrome浏览器静默模式启动(headless)
前言 selenium+phantomjs可以打开无界面的浏览器,实现静默模式启动浏览器完成自动化测试,这个模式是极好的,不需要占用电脑的屏幕. 但是呢,phantomjs这个坑还是比较多的,并且遇到 ...
- 类继承-super, 私有变量
多继承 class A: def ces(self): print('a-ces') class B(A): def ces(self): print('b-ces') class C(A): def ...
- bootstrap3中模态框的数据编辑使用方法
模态框是bootstrap3中比较好用得弹窗控件,这回使用了 说主要的,官方详细教程 http://www.runoob.com/bootstrap/bootstrap-modal-plugin.ht ...