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

3
6 11 12

Sample Output

0.090909090909

HINT

题意

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

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

题解:

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

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

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std;
const int maxn = + ;
double dp[][];
int p[maxn],n,cur=; double cal(int x,int y)
{
int tx = abs(y-x);
return (double)tx/(double)x;
} void init_()
{
for(int i = ; 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 = ; i < n ; ++ i) scanf("%d",p+i);
init_();dp[cur][] = ;
for(int i = ; i < n ; ++ i)
{
int pre = cur;cur ^= ;init_();
for(int j = ; 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 = ; j <= 2e5 ; ++ j) ans = min(ans , dp[cur][j]);
printf("%.12lf\n",ans);
return ;
}

Aizu 2305 Beautiful Currency DP的更多相关文章

  1. Aizu - 2305 Beautiful Currency (二分 + DFS遍历)

    F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...

  2. 【Aizu 2305】Beautiful Currency

    题 题意 给你n个货币价格,然后通过调整一些货币的大小,使得所有比自己小的货币都是该货币的约数,调整前第 i 货币为a,调整后为b 那么变化率为 ri=|a-b|/a ,总变化率为max(ri).求最 ...

  3. Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组

    题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...

  4. Problem D. What a Beautiful Lake dp

    Problem D. What a Beautiful Lake Description Weiming Lake, also named "Un-named Lake", is ...

  5. SGU 199 Beautiful People(DP+二分)

    时间限制:0.25s 空间限制:4M 题意: 有n个人,每个人有两个能力值,只有一个人的两个能力都小于另一个的能力值,这两个人才能共存,求能同时共存的最大人数. Solution: 显然这是一个两个关 ...

  6. Codeforces 1155 D Beautiful Array DP,最大子段和

    题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...

  7. D. Beautiful Array DP

    https://codeforces.com/contest/1155/problem/D 这个题目还是不会写,挺难的,最后还是lj大佬教我的. 这个题目就是要分成三段来考虑, 第一段就是不进行乘,就 ...

  8. CodeForces - 55D(数位dp,离散化)

    题目来源:http://codeforces.com/problemset/problem/55/D Volodya is an odd boy and his taste is strange as ...

  9. cf 403 D

    D. Beautiful Pairs of Numbers time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. C#中的AssemblyInfo 程序集信息

    [VS软件版本号定义.规则和相关的Visual Studio插件](http://blog.csdn.net/cnhk1225/article/details/37500593) [assembly: ...

  2. acdream 瑶瑶带你玩激光坦克 (模拟)

    瑶瑶带你玩激光坦克 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 256000/128000KB (Java/Others) Submi ...

  3. HDU 5675 ztr loves math

    ztr loves math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. JRebel 5.3.2

    http://www.blogjava.net/xylz/archive/2013/09/15/404098.html   此为单文件版本,无需license文件 IDE(Eclipse.IDEA可能 ...

  5. PHP 实现短域名互转

    /** * 短域名生成&解析类 */ class Build_URL { private $mem; private $base_url = 'http://xxx.com/'; public ...

  6. C# 多线程 方法,类的标记

    [MethodImplAttribute(MethodImplOptions.Synchronized)] 此标记可用于方法,将一个方法标记为单线程进入,但在多个实例的时候仍有可能导致问题,比较有共享 ...

  7. 50道经典的JAVA编程题(31-35)

    50道经典的JAVA编程题(31-35),今天考完了java,在前篇博客里面贴出了题了,见:<今天考试的JAVA编程题>.考完了也轻松了,下个星期一还考微机原理呢,啥都不会,估计今天就做到 ...

  8. 使用slf4j取代Apache Commons Logging

    假如你正在开发应用程序所调用的组件当中已经使用了 JCL(之前叫 Jakarta Commons Logging,JCL) 的,还有一些组建可能直接调用了 java.util.logging,这时你需 ...

  9. [读书笔记]了不起的node.js(二)

    这周做项目做得比较散(应该说一直都是这样),总结就依据不同情境双开吧-这篇记录的是关于node的学习总结,而下一篇是做项目学到的web前端的知识. 1.HTTP篇 node的HTTP模块在第一篇时接触 ...

  10. MapReduce 开发环境搭建(Eclipse\MyEclipse + Maven)

    写在前面的话 可详细参考,一定得去看 HBase 开发环境搭建(Eclipse\MyEclipse + Maven) Zookeeper项目开发环境搭建(Eclipse\MyEclipse + Mav ...