555555,能避开精度还是避开精度吧,,,,我们是弱菜。。

Poor Warehouse Keeper

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1672    Accepted Submission(s): 463

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?
 
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.
 
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 1 3 8 9 31
 
Sample Output
0 5 11

Hint

For the second test case, one way to achieve is: (1, 1) -> (1, 2) -> (2, 4) -> (2, 5) -> (3, 7.5) -> (3, 8.5)

 
Source
 
Recommend
liuyiding
 

一个机器,只有两个按钮,上面的按钮表示数量,下面的表示总价(只显示整数部分)

开始的时候数量和总价都是1,单价为1,然后进行一些操作,让数量变成x,总价变成y,求得是最小操作次数。

如果按数量键,表示增加一个物品,单价不变,数量+1,那么总价=总价/数量*(数量+1),并且显示新的数量

如果按总价键,单价=(总价+1)/数量,那么总价=总价+1,并且显示总价的整数部分。

x很小y很大,暴力宽搜TLE了。

换个角度,求最小操作次数 换成  求最小合法单价的操作次数

因为最终得到了x数量,y的总价,对于一个单价tp,如果tp*x的整数部分==y那么这个单价就是可以的。

而最小操作次数一定是 得到最小合法单价的操作次数。

对于两种操作,按数量键并不会影响单价,按总价键会增加单价,而且增加单价的幅度是随着操作次数增多而下降的,按下数量键会是这个幅度下降的更多。

这样,一共要按下x-1次数量键,每次按数量键前尽量多的按总价键(保证该单价下的x个数量物品不会超过y元),最后会得到一个不超过目标单价(y/x)的最大单价z,该单价下的总价值为z*n如果z*n<y则还需要按下若干次总价键。

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<string>
//#include<pair> #define N 1005
#define M 1000005
#define mod 1000000007
#define inf 0x3f3f3f3f
//#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll mul=;
ll x,y;
ll ans;
ll tmi,tma;
ll dmi,dma;
ll dan;
ll num,tot; void ini()
{
ans=;
tmi=y*mul;
tma=(y+)*mul;
dmi=tmi/x;
dma=tma/x;
num=;
dan=mul;
tot=mul;
} void solve()
{
ans=x-;
ll k1,k2;
ll te;
if(dan>=dma){
ans=-;return;
}
for(num=;num<=x;num++){
te=mul/num;
if(dan>=dmi) break;
k1=(dmi-dan+te-)/te;
k2=(dma-dan+te-)/te;
// printf(" num=%I64d ans=%I64d dan=%I64d dmi=%I64d dma=%I64d te=%I64d k1=%I64d k2=%I64d\n",
// num,ans,dan,dmi,dma,te,k1,k2);
if(k1!=k2){
ans+=k1;
dan+=k1*mul/num;
return;
}
else{
dan+=(k1-)*te;
ans+=(k1-);
}
}
} void out()
{
printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
// for(int ccnt=1;ccnt<=T;ccnt++)
// while(T--)
while(scanf("%I64d%I64d",&x,&y)!=EOF)
{
//if(n==0 && k==0 ) break;
//printf("Case %d: ",ccnt);
ini();
solve();
out();
} return ;
}

HDU 4803 Poor Warehouse Keeper (贪心+避开精度)的更多相关文章

  1. hdu 4803 Poor Warehouse Keeper(贪心+数学)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26005267 题目链接:hdu 4803 P ...

  2. HDU 4803 Poor Warehouse Keeper(贪心)

    题目链接 题意 :屏幕可以显示两个值,一个是数量x,一个是总价y.有两种操作,一种是加一次总价,变成x,1+y:一种是加一个数量,这要的话总价也会相应加上一个的价钱,变成x+1,y+y/x.总价显示的 ...

  3. HDU 4803 Poor Warehouse Keeper

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4803 解题报告:有一个记录器,一共有两个按钮,还有两行屏幕显示,第一行的屏幕显示的是数目,第二行的屏幕 ...

  4. HDU - 4803 - Poor Warehouse Keeper (思维)

    题意: 给出x,y两个值分别代表x个物品,总价为y 有两种变化: 1.使总价+1,数量不变 2.数量+1,总价跟着变化 (y = y + y / x) 思路: 给出目标x,y,计算最少变化次使数量变化 ...

  5. 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...

  6. Poor Warehouse Keeper

    Poor Warehouse Keeper http://acm.hdu.edu.cn/showproblem.php?pid=4803 Jenny is a warehouse keeper. He ...

  7. HDU 4952 Poor Mitsui(贪心)

    HDU 4957 Poor Mitsui pid=4957" style="">题目链接 思路:利用相邻交换法去贪心就可以.注意容积为0的情况,这是个坑点 代码: ...

  8. 【贪心】hdu4803 Poor Warehouse Keeper

    题意:一开始有1个物品,总价是1.你的一次操作可以要么使得物品数量+1,总价加上当前物品的单价.要么可以使得总价+1,物品数量不变.问你最少要几次操作从初始状态到达有x个物品,总价是y的状态.这里的y ...

  9. HDU 4802 && HDU 4803 贪心,高精 && HDU 4804 轮廓线dp && HDU 4805 计算几何 && HDU 4811 (13南京区域赛现场赛 题目重演A,B,C,D,J)

    A.GPA(HDU4802): 给你一些字符串对应的权重,求加权平均,如果是N,P不计入统计 GPA Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. mac上使用命令行显示隐藏文件

    终端中输入命令 打开<终端> - 粘贴下面的两行命令执行 defaults write com.apple.finder AppleShowAllFiles TRUEkillall Fin ...

  2. 团队作业-Beta冲刺第一天

    这个作业属于哪个课程 <https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1> 这个作业要求在哪里 <https ...

  3. JSONP 跨域请求 - 获取JSON数据

    如何用原生方式使用JSONP? 下边这一DEMO实际上是JSONP的简单表现形式,在客户端声明回调函数之后,客户端通过script标签向服务器跨域请求数据,然后服务端返回相应的数据并动态执行回调函数. ...

  4. 实 Jordan 标准型和实 Weyr 标准型

    将学习到什么 本节讨论关于实矩阵的实形式的 Jordan 标准型,也讨论关于复矩阵的另外一种形式的 Jordan 标准型,因为它在与交换性有关的问题中很有用.   实 Jordan 标准型 假设 \( ...

  5. Robotium实践之路源码创建测试项目

    1.JDK安装及环境配置 2.Eclipse安装 3.ADT插件安装 4.模拟器安装 5.准备源码 6.引进源码置项目中 .文件 .导入 .选择现有项目置工作空间中 .浏览 .选择项目,选择模拟器版本 ...

  6. [LUOGU] P2759 奇怪的函数

    题目描述 使得 x^x x x 达到或超过 n 位数字的最小正整数 x 是多少? 输入输出格式 输入格式: 一个正整数 n 输出格式: 使得 x^xx x 达到 n 位数字的最小正整数 x 输入输出样 ...

  7. (12)zabbix agent 类型所有key

    zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据,agent分为两个版本,其中一个是主动一个是被动,在配置主机我们可以看到一个是agent,另一个是agent(activ ...

  8. linux各种终端类型的区别和概念

    1 pty(虚拟终端或伪终端): 当我们远程telnet到主机或使用xterm时不也需要一个终端交互么?是的,这就是虚拟终端pty(pseudo-tty). 2 tty(终端设备的统称):tty一词源 ...

  9. python爬虫(爬取图片)

    python爬虫爬图片 爬虫爬校花网校花的图片 第一步 载入爬虫模块 #载入爬虫模块 import re #载入爬虫模块 import requests #载入爬虫模块 第二步 获得校花网的地址,获得 ...

  10. Lecture1 实验过程模型

    Part 1 基本概念 因变量:待检验理论重点关注的,受多个变量影响的变量.(实际考察的,结果) 自变量:影响因变量变化的变量. 因子:重点关注的自变量. 控制变量(control variables ...