博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Aizu 2305 Beautiful Currency DP
阅读量:6844 次
发布时间:2019-06-26

本文共 2954 字,大约阅读时间需要 9 分钟。

Beautiful Currency

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93265#problem/F

Description

KM country has N kinds of coins and each coin has its value a_i.

The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins.

A currency system is called beautiful if each coin has an integer value and the (i+1)-th smallest value is divisible by the i-th smallest value for all i (1 \leq i \leq N-1).

For example, the set {1, 5, 10, 50, 100, 500} is considered as a beautiful system, while the set {1, 5, 10, 25, 50, 100} is NOT, because 25is not divisible by 10.

Since changing the currency system may confuse citizens, the king, Kita_masa, wants to minimize the maximum value of the confusion ratios. Here, the confusion ratio for the change in the i-th coin is defined as |a_i - b_i| / a_i, where a_i and b_i is the value of i-th coin before and after the structure changes, respectively.

Note that Kita_masa can change the value of each existing coin, but he cannot introduce new coins nor eliminate existing coins. After the modification, the values of two or more coins may coincide.

Input

Each dataset contains two lines. The first line contains a single integer, N, and the second line contains N integers, {a_i}.

You may assume the following constraints:

1 \leq N \leq 20

1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5

Output

Output one number that represents the minimum of the maximum value of the confusion ratios. The value may be printed with an arbitrary number of decimal digits, but may not contain an absolute error greater than or equal to 10^{-8}.

Sample Input

36 11 12

Sample Output

0.090909090909

HINT

 

题意

有一个国家,要创造完美的货币制度,货币制度完美,就是要第i面值的钱,能够整除i-1面值的钱

然后代价是|bi-ai|/ai,问你能够更待的策略中,最小的的最大代价是多少

题解:

DP转移,枚举金钱,首先,纸币的面值不可能超过2e5,因为这样,还不如全部变成1

然后我们直接类似筛法一样转移就好了

代码:

#include 
#include
#include
#include
using namespace std;const int maxn = 20+ 15;double dp[2][200050];int p[maxn],n,cur=0;double cal(int x,int y){ int tx = abs(y-x); return (double)tx/(double)x;}void init_(){ for(int i = 0 ; i <= 2e5 ; ++ i) dp[cur][i] = 1e233;}inline void updata(double & x,double v){ x = min(x,v);}int main(int argc,char * argv[]){ scanf("%d",&n); for(int i = 0 ; i < n ; ++ i) scanf("%d",p+i); init_();dp[cur][1] = 0; for(int i = 0 ; i < n ; ++ i) { int pre = cur;cur ^= 1;init_(); for(int j = 0 ; j <= 2e5 ; ++ j) if(dp[pre][j] < 1e23) { int fs = j; while(fs <= 2e5) { updata(dp[cur][fs],max(dp[pre][j],cal(p[i],fs))); fs += j; } } } double ans = 1e233; for(int j = 0 ; j <= 2e5 ; ++ j) ans = min(ans , dp[cur][j]); printf("%.12lf\n",ans); return 0;}

 

转载地址:http://svsul.baihongyu.com/

你可能感兴趣的文章
Spring MVC 使用拦截器 HiddenHttpMethodFilter配置Rest风格的URL
查看>>
idea中查看方法的调用链
查看>>
【Boost】boost::string_algo详解2——find相关函数
查看>>
BZOJ 1488: [HNOI2009]图的同构 polay
查看>>
Setting up Hudson on port 80 on a Debian or Ubuntu machine
查看>>
Java get yesterday's date
查看>>
分享一些非常好用的Visual Studio扩展
查看>>
给大家分享一个培训的PPT:面向构件的组织级开发模式探讨
查看>>
提供了SDL非常多的基础功能、包括画线画圆各种函数包和缩放图形!
查看>>
在网页中显示数学符号
查看>>
实体类与xml互相转换通用 .
查看>>
IE中的隐私策略
查看>>
利用mapreduce将数据从hdfs导入到hbase遇到的问题
查看>>
Gnu Linux--Ubuntu系统清理项整理
查看>>
JDK 工具列表
查看>>
[Angular 2] Rendering an Observable with the Async Pipe
查看>>
Launch和Shut Off操作详解 - 每天5分钟玩转 OpenStack(30)
查看>>
HibernateTool的安装和使用(Eclipse中)
查看>>
开发原则之约定大于配置
查看>>
iOS - App 与外设间的通信方式
查看>>