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 ...
随机推荐
- Android开发UI之textview实现高亮显示并点击跳转
textview实现高亮显示,带下划线,带背景,主要是通过SpannableString类实现. 具体实现请看代码: TextView showMoreContent=(TextView)findvi ...
- pylinter could not automatically determined the path to `lint.py`
先关闭Sublime Text 1) 到官网先下载pylinter,http://www.logilab.org/project/pylint,然后解压缩,拷贝到C盘,目录为C:\pylint-1.0 ...
- Oracle Length 和 Lengthb 函数说明 .(用来判断记录值里是否有中文内容)
一.官网的说明 http://download.oracle.com/docs/cd/E11882_01/server.112/e26088/functions088.htm#SQLRF00658 P ...
- 初探数位dp
数位dp有着很明显的特点,一般来说是给定区间[l,r]求满足某种条件区间中的数有多少个 朴素解法一般是O(n)的而n往往很大(10^8起步) 这时候我们就要想办法优化,于是就有了数位dp 数位有两个基 ...
- 利用icepdf将pdf文件转为图片
所需jar 包为icepdf-core.jar.icepdf-extra.jar.icepdf-pro-intl.jar.icepdf-pro.jar和icepdf-viewer.jar. 示例代码如 ...
- SpannableStringBuilder 和 SpannableString
EditText: 通常用于显示文字,但有时候也需要在文字中夹杂一些图片,比如QQ中就可以使用表情图片,又比如需要的文字高亮显示等等,如何在android中也做到这样呢? 记得andr ...
- STL序列式容器
1.vector 空间运用的灵活性. 实现技术——关键是对大小的控制以及重新配置时的数据移动效率. 配置新空间.数据移动.释还旧空间 erase(int pos ...
- Linq 两个集合模糊查询
1.Linq的likelist<string> l=new list<string>();l.add("ss")l.add("ss123" ...
- python包管理工具
pip 是一个安装和管理 Python 包的工具 , 是 easy_install 的一个替换品.本文将详细说明 安装 pip 的方法和 使用 pip 的一些基本操作如安装.更新和卸载 python ...
- jsp:forward与缓冲区
jsp:forward的作用是在服务器端进行页面跳转.通常有<jsp:forward page="NewPage.jsp">语句的页面的在执行时会提前执行跳转,而不输出 ...