HDU 4803 Poor Warehouse Keeper(贪心)
来源:互联网 发布:ecshop大京东2.5源码 编辑:程序博客网 时间:2024/05/01 07:33
题意:
让你按如题所示的两个按钮,初始情况是1 1,问你最少多少次可以把他按成x y。
这个贪心策略还是略机智的,因为上面一个按钮会影响下面的,而下面的只会影响单价,所以我们要尽量是下面的变大,达到一个最大值,然后上面的只要按几次就能达到了。
但是下面的也不能太大,不然等上面的按钮达到要求之后,就会使得下面的溢出了,所以我们每次在按上面按钮之前让下面的达到尽量大就可以了。
代码:
//// Created by CQU_CST_WuErli// Copyright (c) 2016 CQU_CST_WuErli. All rights reserved.//#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <string>#include <vector>#include <list>#include <map>#include <queue>#include <stack>#include <set>#include <algorithm>#include <sstream>#define CLR(x) memset(x,0,sizeof(x))#define OFF(x) memset(x,-1,sizeof(x))#define MEM(x,a) memset((x),(a),sizeof(x))#define BUG cout << "I am here" << endl#define lookln(x) cout << #x << "=" << x << endl#define SI(a) scanf("%d",&a)#define SII(a,b) scanf("%d%d",&a,&b)#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)#define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1#define Root 1,n,1#define BigInteger bignconst int MAX_L=2005;// For BigIntegerconst int INF_INT=0x3f3f3f3f;const long long INF_LL=0x7fffffff;const int MOD=1e9+7;const double eps=1e-6;const double pi=acos(-1);typedef long long ll;using namespace std;int x,y;int main(int argc, char const *argv[]) {#ifdef LOCAL freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin); // freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);#endif while(SII(x,y)==2) { if (x>y) { cout << -1 << endl; continue; } if (x==1) { cout << y-1 << endl; continue; } int ans=x-1; double Maxi=((double)y+1.0-eps)/(double)x; double tmp=1.0; rep(i,1,x) { double now=i*Maxi; int tt=(int)(now-tmp); tmp+=tt; tmp=tmp*(i+1)/i; ans+=tt; } cout << ans << endl; } return 0;}
0 0
- HDU 4803 Poor Warehouse Keeper(贪心)
- hdu 4803 Poor Warehouse Keeper(贪心)
- HDU 4803 Poor Warehouse Keeper(贪心)
- hdu 4803 Poor Warehouse Keeper(贪心+数学)
- HDU - 4803 Poor Warehouse Keeper(贪心)
- [HDU 4803]Poor Warehouse Keeper[贪心]
- hdu 4803 Poor Warehouse Keeper (贪心思维)
- hdu 4803 Poor Warehouse Keeper(贪心)
- HDU 4803 Poor Warehouse Keeper(贪心)
- HDU 4803Poor Warehouse Keeper(数学题)
- HDU 4803 Poor Warehouse Keeper
- HDU 4803 Poor Warehouse Keeper
- HDU 4803 Poor Warehouse Keeper 贪心 二分搜索
- [hdu 4803]Poor Warehouse Keeper 进制相关 贪心
- BNUOJ 34025 -Poor Warehouse Keeper(贪心)
- HDU 4803 Poor Warehouse Keeper(打表找规律)
- Poor Warehouse Keeper hdu 4803(思维,卡精度)
- HDU——4803 Poor Warehouse Keeper
- 线程池原理
- 《一个勺子》观后感
- OpenCV实践之路——画出时钟并动态同步系统时间
- vim+python+OpenCV学习四 : 像素通道分割
- Pots(bfs恶心的宽搜)
- HDU 4803 Poor Warehouse Keeper(贪心)
- Create blog posts from RStudio to WordPress
- ifconfig配置网络时,出现“SIOCSIFADDR: No such device”和“eth0:ERROR while getting interface flags:No such dev”
- ajax原理和XmlHttpRequest对象
- 准备1千万个随机数字,保存到文件并顺序读取
- 数组溢出与指针问题
- 从两段代码中理解JavaScript的单线程和异步
- Java中数字格式化问题
- Android Studio 报:AndroidManifest.xml (系统找不到指定的路径。) 错误