Aizu 2305 Beautiful Currency DP
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
然后我们直接类似筛法一样转移就好了
@)1%KBO0HM418$J94$1R.jpg)
代码:
#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的更多相关文章
- Aizu - 2305 Beautiful Currency (二分 + DFS遍历)
F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit intege ...
- 【Aizu 2305】Beautiful Currency
题 题意 给你n个货币价格,然后通过调整一些货币的大小,使得所有比自己小的货币都是该货币的约数,调整前第 i 货币为a,调整后为b 那么变化率为 ri=|a-b|/a ,总变化率为max(ri).求最 ...
- Codeforces 1085G(1086E) Beautiful Matrix $dp$+树状数组
题意 定义一个\(n*n\)的矩阵是\(beautiful\)的,需要满足以下三个条件: 1.每一行是一个排列. 2.上下相邻的两个元素的值不同. 再定义两个矩阵的字典序大的矩阵大(从左往右从上到下一 ...
- Problem D. What a Beautiful Lake dp
Problem D. What a Beautiful Lake Description Weiming Lake, also named "Un-named Lake", is ...
- SGU 199 Beautiful People(DP+二分)
时间限制:0.25s 空间限制:4M 题意: 有n个人,每个人有两个能力值,只有一个人的两个能力都小于另一个的能力值,这两个人才能共存,求能同时共存的最大人数. Solution: 显然这是一个两个关 ...
- Codeforces 1155 D Beautiful Array DP,最大子段和
题意 给出一个长度为\(n\)的数列和数字\(x\),经过最多一次操作将数列的一个子段的每个元素变为\(a[i]*x\),使该数列的最大子段和最大 分析 将这个数列分为3段考虑,第一段和第三段是未修改 ...
- D. Beautiful Array DP
https://codeforces.com/contest/1155/problem/D 这个题目还是不会写,挺难的,最后还是lj大佬教我的. 这个题目就是要分成三段来考虑, 第一段就是不进行乘,就 ...
- CodeForces - 55D(数位dp,离散化)
题目来源:http://codeforces.com/problemset/problem/55/D Volodya is an odd boy and his taste is strange as ...
- cf 403 D
D. Beautiful Pairs of Numbers time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- ORA-14452: 试图创建, 更改或删除正在使用的临时表中的索引
ORA-14452: 试图创建, 更改或删除正在使用的临时表中的索引 因为表KOL_XX_FIN050_TEMP 为临时表,而且有其他session正在使用. 处理步骤: 1.先从 dba ...
- Anti-pattern(反面模式)
转自维基百科 http://zh.wikipedia.org/wiki/%E5%8F%8D%E9%9D%A2%E6%A8%A1%E5%BC%8F 在软件工程中,一个反面模式(anti-pattern或 ...
- hud 3336 count the string (KMP)
这道题本来想对了,可是因为hdu对pascal语言的限制是我认为自己想错了,结果一看题解发现自己对了…… 题意:给以字符串 计算出以前i个字符为前缀的字符中 在主串中出现的次数和 如: num(aba ...
- C# 判断两张图片是否一致的快速方法
#region 判断图片是否一致 /// <summary> /// 判断图片是否一致 /// </summary> /// <param name="img& ...
- Java中的volatile
关于volatile 在JVM 1.2之前,Java的内存模型实现总是从主存读取变量,是不需要进行特别的注意的.而随着JVM的成熟和优化,现在在多线程环境下 volatile关键字的使用变得非常重要. ...
- (八)学习CSS之line-style-type属性
参考:http://www.w3school.com.cn/cssref/pr_list-style-type.asp 设置不同的列表样式: ul.circle {list-style-type:ci ...
- Ildasm.exe(MSIL 反汇编程序)
MSIL 反汇编程序是 MSIL 汇编程序 (Ilasm.exe) 的伙伴工具. Ildasm.exe 采用包含 Microsoft 中间语言 (MSIL) 代码的可迁移可执行 (PE) 文件,并创建 ...
- delphi获得当前鼠标坐标
简单的说就是取鼠标所在位置对应的窗口句柄? procedure TForm1.Timer1Timer(Sender: TObject);vara:TPoint; //用来存放坐标hw:HWND; // ...
- 【转】java list用法示例详解
转自:http://www.jb51.net/article/45660.htm java中可变数组的原理就是不断的创建新的数组,将原数组加到新的数组中,下文对java list用法做了详解. Lis ...
- NOIP2004 合并石子
二.合并果子 (fruit.pas/dpr/c/cpp) [问题描述] 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多 ...