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次下键,由于上键的次数是确定的,所以最 ...
随机推荐
- python logging 日志模块的配置和使用
import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(line ...
- 同一个IP段ping不通同事的电脑
原因居然是同事的防火墙打开了. windows关闭防火墙的教程,请自行百度.
- Koa 框架整理
学习交流 Koa使用了ES6规范的generator和异步编程是一个更轻量级Web开发的框架,Koa 的先天优势在于 generator.由于是我个人的分享交流,所以Node基础.ES6标准.Web开 ...
- Python3 引入sqlite3时出现错误:ModuleNotFoundError: No module named '_sqlite3'
在Python3 中内置了SQLite3,但是在编译安装完之后执行: import sqlite3 出现错误: ModuleNotFoundError: No module named '_sqlit ...
- Python之——遇到的小知识点总结
学习过程中,难免会遇到一些冷门的小知识点,熟悉这些小知识可以在工作中达到事半功倍的效果,尽力消除自己的知识盲区.总之当时的自己花了不少功夫去解决这些问题,因此觉得有必要单独记录下来,以后也许会再遇到, ...
- idea-activate code
N757JE0KCT-eyJsaWNlbnNlSWQiOiJONzU3SkUwS0NUIiwibGljZW5zZWVOYW1lIjoid3UgYW5qdW4iLCJhc3NpZ25lZU5hbWUiO ...
- python学习笔记一和PHP的一些对比
python和php一样是 解释性语言 php和php一样 定义变量不需要指定类型,C语言中的print函数 在python中也是适用的 python编码 适用缩进 4个空格,通常存储为UTF-8模 ...
- IOS CFBundleIdentifier
CFBundleIdentifier CFBundleIdentifier 必须是com.12306.aaa 这样的格式吗 AppID 用通配符格式的AppID方便. AppSt ...
- bat 笔记 一
echo 有两个参数 off 和 on 注意echo前面要加个@才生效 当 @echo off的时候就是将doc命令将前面的路径去掉,默认其实就是@echo on显示路径: 默认的状态: 输入@ech ...
- jetty异常
异常一: java.net.BindException: Address already in use: bind jvm 1 | 2017-10-18 15:08:10,792+0800 WARN ...