text stringlengths 49 983k |
|---|
#include<bits/stdc++.h>
using namespace std;
int N;
int A[22];
/*
double dp[2][2*100000+1];
double solve(int id,int dv){
fill(dp[0],dp[2],1e15);
double res = 1e15;
for(int i=0;i<20;i++){
int id = i&1;
int nd = (i+1)&1;
for(int j=0;j<=(1<<20);j++) dp[nd][j]=1e15;
for(int dv=1;dv<=(1<<20);dv++){
if( dp[id][dv] < -1e-9 ) continue;
if( dp[id][dv] > res ) continue;
printf("dp[%d][%d] = %.9lf\n",i,dv,dp[id][dv]);
if( id == N ) return dp[id][dv] = 0.0f;
for(int j=dv;j<=(1<<20);j+=dv){
dp[nd][j] = min( dp[nd][j], max( dp[id][dv],
abs(A[i]-j)/(double)A[i]) );
res = min(dp[nd][j],res);
}
}
}
return res;
double ret = 1e15;
for(int i=0;i<=(1<<20);i++) ret = min( ret, dp[N&1][i] );
return ret;
}
*/
double dp[21][200001];
double solve(int id,int dv){
if( dp[id][dv] > -1e-9 ) return dp[id][dv];
if( id == N ) return dp[id][dv] = 0.0;
double ret = 1e15;
for(int i=dv;i<A[id]*2;i+=dv){
ret = min( ret,
max( solve(id+1,i), abs(A[id]-i)/(double)A[id]) );
}
return dp[id][dv] = ret;
}
int main(){
scanf("%d",&N);
for(int i=0;i<N;i++) scanf("%d",&A[i]);
fill(dp[0],dp[N],-1.0);
printf("%.10lf\n",solve(0,1));
} |
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#define INF 1e10
using namespace std;
int n;
int a[22];
double dp[200001][21];
int main(void){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<=200000;i++){
dp[i][0]=0;
for(int j=1;j<=n;j++){
dp[i][j]=INF;
}
}
for(int i=1;i<=200000;i++){
for(int j=0;j<n;j++){
double cost=(double)abs(a[j]-i)/a[j];
for(int k=1;i*k<=200000;k++){
dp[i*k][j+1]=min(dp[i*k][j+1],dp[i][j]);
dp[i*k][j+1]=min(dp[i*k][j+1],dp[i][j]);
}
dp[i][j+1]=max(dp[i][j+1],cost);
}
}
double res=INF;
for(int i=1;i<=200000;i++){
res=min(res,dp[i][n]);
}
printf("%.10f\n",res);
return 0;
} |
#include<bits/stdc++.h>
/*
*/
using namespace std;
int main() {
int N;
cin >> N;
vector<int>D( N );
for( size_t i = 0; i < N; i++ ) {
cin >> D[i];
}
double maxans = 1, minans = 0;
for( size_t idx = 0; idx < 1000; idx++ ) {
double midans = ( maxans + minans ) / 2;
set<int>prev;
prev.insert( 1 );
for( size_t i = 0; i < N; i++ ) {
double minvalue = D[i] * ( 1. - midans );
double maxvalue = D[i] * ( 1. + midans );
//cout << fixed << setprecision( 20 ) << minvalue << " " << maxvalue << endl;
set<int>next;
for( auto one : prev ) {
for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
next.insert( j*one );
}
}
prev = next;
}
if( prev.size() ) {
maxans = midans;
} else {
minans = midans;
}
}
cout << fixed << setprecision( 20 ) << minans << endl;
} |
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
const int maxn = 22;
const int maxm = 150000;
double dp[maxn][maxm];
int a[maxn];
double rat (int x, int y) {
return 1.0 * abs (x - y) / x;
}
int main () {
int n, i, j, k;
double ans, Min;
while (~scanf ("%d", &n)) {
for (i = 1; i <= n; ++i) scanf ("%d", &a[i]);
memset (dp, 0x7f, sizeof (dp));
for (i = 1; i < maxm; ++i) {
dp[1][i] = rat(a[1], i);
}
for (i = 2; i <= n; ++i) {
//Min = dp[0][0];
for (j = 1; j < maxm; ++j) {
for (k = 1; k * j < maxm; ++k) {
dp[i][k * j] = min (dp[i][k * j], max(dp[i-1][j], rat (a[i], k * j)));
//printf ("%lf %lf %lf\n", dp[i][k * j], dp[i-1][j], rat (a[i], k * j));
//Min = min (Min, dp[i][k * j]);
}
}
//printf ("Min: %lf\n", Min);
}
ans = dp[n][1];
for (j = 2; j < maxm; ++j) {
ans = min (ans, dp[n][j]);
}
printf ("%.12lf\n", ans);
}
return 0;
} |
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using namespace std;
using R=long double;
const int limit=150010;
R dp[20][limit];
int main(void){
int n,a[20];
cin >> n;
rep(i,n) cin >> a[i];
rep(i,n)rep(j,limit) dp[i][j]=1e30;
rep(j,1,limit) dp[0][j]=1.0*abs(j-a[0])/a[0];
rep(i,n-1)rep(j,1,limit){
for(int k=j;k<limit;k+=j){
chmin(dp[i+1][k],max<R>(dp[i][j],1.0*abs(k-a[i+1])/a[i+1]));
}
}
R ans=1.0;
rep(j,1,limit) chmin(ans,dp[n-1][j]);
cout.precision(20);
cout << fixed << ans << endl;
return 0;
} |
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int n, a[20];
double dp[20][150000];
int main(){
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) rep(j, 150000) dp[i][j] = 1;
rep(i, a[0] * 1.5 + 1) dp[0][i] = abs(i - a[0]) * 1.0 / a[0];
rep(i, n - 1) rep(j, a[i] * 1.5 + 1) if(dp[i][j] < 1){
for(int k = 1; k * j <= a[i + 1] * 1.5; k++)
dp[i + 1][k * j] = min(dp[i + 1][k * j], max(dp[i][j], abs(k * j - a[i + 1]) * 1.0 / a[i + 1]));
}
double ans = 1;
rep(i, 150000) ans = min(ans, dp[n - 1][i]);
printf("%.9f\n", ans);
return 0;
} |
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
int n,a[30];
double dp[22][200005],ans;
vector<int>p[200005];
int main()
{
int i,j,k,h;
for(i=1;i<200005;i++)
for(j=i;j<=200000;j+=i) p[j].push_back(i);
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n);
for(i=1;i<=200000;i++) dp[0][i]=(abs(i-a[0])+0.0)/a[0];
for(i=1;i<n;i++)
{
for(j=1;j<=200000;j++)
{
dp[i][j]=100000000.0;
for(k=0;k<p[j].size();k++)
{
dp[i][j]=min(dp[i][j],max(dp[i-1][p[j][k]],(abs(j-a[i])+0.0)/a[i]));
}
}
}
ans=100000000.0;
for(i=1;i<=200000;i++) ans=min(ans,dp[n-1][i]);
printf("%.9lf\n",ans);
return 0;
} |
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cfloat>
using namespace std;
const double INF = DBL_MAX / 2;
int main()
{
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; ++i)
cin >> a[i];
int m = a[n-1] * 2;
vector<double> dp(m, INF);
dp[1] = 0;
for(int i=0; i<n; ++i){
vector<double> nextDp(m, INF);
for(int j=1; j<m; ++j){
for(int k=j; k<m; k+=j){
nextDp[k] = min(nextDp[k], max(dp[j], abs(a[i]-k)/(double)a[i]));
}
}
dp.swap(nextDp);
}
double ret = INF;
for(int i=0; i<m; ++i)
ret = min(ret, dp[i]);
printf("%.10f\n", ret);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FF first
#define SS second
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9+7;
const int MAX = 2e5;
const double INF = 1e15;
double dp[21][200100];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
int N; cin >> N;
VI xs(N); REP(i,N) cin >> xs[i];
fill((double*)dp, (double*)dp+21*200100, INF);
FOR(j,1,MAX+1)
dp[0][j] = abs(j-xs[0]) * 1. / xs[0];
for(int i=0;i<N-1;++i){
for(int j=1;j<=MAX;++j){
if(dp[i][j] < MAX)
for(int k=j;k<=MAX;k+=j){
dp[i+1][k] = min(dp[i+1][k], max(dp[i][j], abs(k-xs[i+1]) * 1. / xs[i+1]));
}
}
}
double res = INF;
REP(j,MAX+1) res = min(res, dp[N-1][j]);
cout << fixed << setprecision(10) << res << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int W = 200000;
int N;
vector<double> A;
double dp[20][W];
int main(){
cout.precision(16);
cout.setf(ios::fixed);
cin >> N;
A.resize(N);
for(auto &v: A) cin >> v;
for(int i=0; i<N; i++)
for(int j=0; j<W; j++)
dp[i][j] = 1e9;
for(int i=0; i<N; i++){
for(int j=1; j<W; j++){
if(0 < i){
for(int k=j; k<W; k+=j)
dp[i][k] = min(dp[i][k], dp[i-1][j]);
}else
dp[i][j] = 0;
dp[i][j] = max(dp[i][j], abs(A[i]-j)/A[i]);
}
}
double ans = 1;
for(int i=0; i<W; i++)
ans = min(ans, dp[N-1][i]);
cout << ans << endl;
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
int main(){
int n;
cin>>n;
vector<int> v(n);
rep(i,n)cin>>v[i];
static double dp[21][200000];
rep(i,21)rep(j,200000)dp[i][j]=INF;
dp[0][1] = 0;
rep(item,n){
for(int val = 1;val<200000;val++){
for(int k=1;val*k<200000;k++){
dp[item+1][val*k] = min(dp[item+1][val*k], max(dp[item][val],(double)abs(val*k-v[item])/v[item]));
}
}
}
double ans = INF;
rep(i,200000)ans = min(dp[n][i],ans);
printf("%.20lf\n",ans);
}
|
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
const int MAXN = 22;
const int MAX = 202000;
double dp[MAXN][MAX];
vi dd[MAX];
vi divs(int n) {
vi ret;
for (int i = 1; i*i <= n; i++) {
if (n%i == 0) {
ret.push_back(i);
if (i*i < n) ret.push_back(n / i);
}
}
return ret;
}
int main() {
for (int i = 1; i < MAX; i++)
dd[i] = divs(i);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
reverse(A.begin(), A.end());
for (int i = 0; i < N; i++) for (int j = 0; j < MAX; j++)
dp[i][j] = 1;
for (int i = 1; i < 2 * A[0]; i++) {
dp[0][i] = 1.*abs(i - A[0]) / A[0];
}
for (int i = 0; i < N-1; i++) {
for (int j = 1; j < 2 * A[i]; j++) if (dp[i][j] < 1) {
for (int d : dd[j]) {
double tmp = max(dp[i][j], 1.*abs(A[i + 1] - d) / A[i + 1]);
dp[i + 1][d] = min(dp[i + 1][d], tmp);
}
}
}
double ans = 1;
for (int i = 0; i < MAX; i++)
ans = min(ans, dp[N - 1][i]);
printf("%.10lf\n", ans);
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
double cost(int a, int b)
{
// a -> b
return double(abs(a - b)) / double(a);
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
vector<vector<double>> dp(N, vector<double>(200001, INF));
// div[i] := i の約数
vector<vector<int>> div(200001);
for (int i = 1; i <= 200000; i++)
{
for (int j = 1; j * j <= i; j++)
{
if (i % j)
continue;
div[i].push_back(j);
if (i != j * j)
div[i].push_back(i / j);
}
sort(div[i].begin(), div[i].end());
}
for (int j = 1; j <= 200000; j++)
{
dp[0][j] = cost(a[0], j);
}
for (int i = 1; i < N; i++)
{
for (int j = 1; j <= 200000; j++)
{
double c = cost(a[i], j);
for (auto v : div[j])
{
dp[i][j] = min(dp[i][j], max(dp[i - 1][v], c));
}
}
}
double res = INF;
for (int i = 1; i <= 200000; i++)
{
res = min(res, dp[N - 1][i]);
}
cout << fixed << setprecision(10) << res << endl;
}
|
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define S_queue<P> priority_queue<P, vector<P>,greater<P> >
#define FIN freopen("D://imput.txt", "r", stdin)
typedef long long LL;
typedef pair<int, int > PII;
typedef unsigned long long uLL;
template<typename T>
void print(T* p, T* q, string Gap = " "){int d = p < q ? 1 : -1;while(p != q){cout << *p;p += d;if(p != q) cout << Gap; }cout << endl;}
template<typename T>
void print(const T &a, string bes = "") {int len = bes.length();if(len >= 2)cout << bes[0] << a << bes[1] << endl;else cout << a << endl;}
const int INF = 0x3f3f3f3f;
const int MAXM = 2e1 + 5;
const int MAXN = 1e2 + 5;
const double eps = 1e-8;
int A[MAXM], n;
double M;
bool DFS(int x, int id, double Max, double m){
if(id >= n) {
M = min(Max, M);
return true;
}
bool flag = false;
int f = (int)(A[id] * m);
int cnt = 1,Ma = A[id] + f,Mi = A[id] - f > 1 ? A[id] - f: 1;
while(cnt * x <= Ma){
if(cnt * x < Mi) {
cnt ++;
continue;
}
if(cnt * x >= Mi && cnt * x <= Ma){
double f_t = fabs(cnt * x - A[id]) / A[id] * 1.0;
if(DFS(cnt * x, id + 1, max(Max, f_t), m)) {
flag = true;
}
}
cnt ++;
}
return flag;
}
bool C(double m){
bool flag = false;
int f = (int)(A[0] * m);
int Mi = A[0] - f > 1? A[0] - f : 1, Ma = A[0] + f;
for(int i = Mi;i <= Ma;i ++){
if(DFS(i, 1, fabs(A[0] - i) / A[0] * 1.0, m)) {
flag = true;
}
}
return flag;
}
int main(){
//FIN;
while(cin >> n){
for(int i = 0;i < n;i ++){
cin >> A[i];
}
M = INF;
double lb = -1,ub = 1.0;
while(ub - lb > eps){
double mid = (ub + lb) / 2.0;
if(C(mid)) ub = mid;
else lb = mid;
}
printf("%.12lf\n", M);
}
return 0;
} |
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
for(T& x: v){ is >> x; } return is;
}
double getRatio(double a, double b){
return abs(a - b) / a;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
cin >> a;
vector<vector<double>> dp(n, vector<double>(200000, numeric_limits<double>::max()));
rep(i,n){
range(j,1,200000){
if(i == 0){
dp[i][j] = getRatio(a[i], j);
}else{
for(int k = j; k < 200000; k+=j){
dp[i][k] = min(dp[i][k], max(dp[i - 1][j], getRatio(a[i], k)));
}
}
}
}
cout << fixed << setprecision(10) << *min_element(all(dp[n - 1])) << endl;
}
|
/*
Aizu 2305
*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#define INF 1.0
using namespace std;
int n,i,j,k,original[21];
double dp[21][200050],result = INF;
int main()
{
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&original[i]);
for (i=1;i<2*original[1];i++)
dp[1][i] = fabs(i-original[1])/original[1];
for (i=2;i<=n;i++)
for (j=1;j<2*original[i];j++)
dp[i][j] = INF;
for (i=2;i<=n;i++)
{
for (j=1;j<2*original[i-1];j++)
{
for (k=j;k<2*original[i];k+=j)
dp[i][k] = min(dp[i][k],max(dp[i-1][j],fabs(k-original[i])/original[i]));
}
}
for (i=1;i<2*original[n];i++) result = min(result,dp[n][i]);
printf("%.10f",result);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
typedef long long int64;
const int INF = 1 << 30;
int N, a[20];
double dp[20][200001];
int main(){
fill_n( *dp, 20 * 200001, (double)INF);
cin >> N;
for(int i = 0; i < N; ++i){
cin >> a[i];
}
for(int i = 1; i < 200001; ++i){
dp[0][i] = fabs(a[0] - i) / a[0];
}
for(int i = 0; i < N - 1; ++i){
for(int j = 1; j < 200001; ++j){
if(dp[i][j] != (double)INF){
for(int k = j; k < 200001; k += j){
dp[i + 1][k] = min( dp[i + 1][k], max( dp[i][j], fabs( a[i + 1] - k) / a[i + 1]));
}
}
}
}
cout << fixed << setprecision(10) << *min_element( dp[N - 1], dp[N]) << endl;
} |
/*
* 2305.cc: Beautiful Currency
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 20;
const int MAX_A = 100000 * 2;
const double DINF = 1e30;
/* typedef */
/* global variables */
int as[MAX_N];
double dp[MAX_N + 1][MAX_A + 1];
/* subroutines */
inline double cratio(int a, int b) { return (double)abs(a - b) / a; }
/* main */
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> as[i];
for (int j = 1; j <= MAX_A; j++) dp[0][j] = cratio(as[0], j);
for (int i = 1; i < n; i++)
for (int j = 1; j <= MAX_A; j++) dp[i][j] = DINF;
for (int i = 0; i < n - 1; i++)
for (int j = 1; j <= MAX_A; j++)
if (dp[i][j] < DINF)
for (int k = j; k <= MAX_A; k += j) {
double dp0 = max(dp[i][j], cratio(as[i + 1], k));
if (dp[i + 1][k] > dp0) dp[i + 1][k] = dp0;
}
double mindp = DINF;
for (int j = 1; j <= MAX_A; j++)
if (mindp > dp[n - 1][j]) mindp = dp[n - 1][j];
printf("%.12lf\n", mindp);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 300000
double dp[30][MAX];
signed main(){
int n;
cin>>n;
double a[n];
for(int i=0;i<n;i++) cin>>a[i];
double INF=1e10;
for(int i=0;i<MAX;i++) dp[0][i]=0;
for(int i=0;i<n;i++){
for(int j=0;j<MAX;j++) dp[i+1][j]=INF;
for(int j=1;j<MAX;j++){
if(dp[i][j]==INF) continue;
//if(j<30) cout<<i<<" "<<j<<":"<<dp[i][j]<<endl;
for(int k=j;k<MAX;k+=j){
dp[i+1][k]=min(dp[i+1][k],max(dp[i][j],abs(a[i]-k)/a[i]));
}
}
}
/*
for(int j=1;j<MAX;j++)
if(j<30) cout<<n<<" "<<j<<":"<<dp[n][j]<<endl;
*/
double ans=INF;
for(int j=0;j<MAX;j++) ans=min(ans,dp[n][j]);
printf("%.12f\n",ans);
return 0;
} |
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cassert>
#include<map>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
const double infty = 1e40;
int path[30];
map<int,double> M[20];
double solve(int n,int now,int prev,const int *in){
if (now < 0)return 0;
map<int,double>::iterator itr = M[now].find(prev);
if (now < n-2){
if (itr != M[now].end()){
return (*itr).second;
}
}
double ret=1e20;
if (now == n-1){
for(int i=1;i<= 1000000;i++){
double tmp = abs((double)i-in[now])/in[now];
if (tmp < ret)ret=min(ret,max(tmp,solve(n,now-1,i,in)));
}
}else {
for(int i=1;(ll)i*i<=prev;i++){
if (prev%i != 0)continue;
double tmp = abs((double)i-in[now])/(double)in[now];
//if (now == 1 && prev == 12)cout <<i <<" " << tmp << endl;
if (tmp < ret)ret=min(ret,max(tmp,solve(n,now-1,i,in)));
//if (now == 0 && prev == 12)cout <<i <<" " << tmp << " " << ret << endl;
if (prev/i != i){
tmp=abs((double)prev/i-in[now])/(double)in[now];
if (tmp < ret)ret=min(ret,max(tmp,solve(n,now-1,prev/i,in)));
//if (now == 1 && prev == 12)cout <<prev/i <<" " << tmp << " " << ret << endl;
//if (now == 0 && prev == 12)cout <<prev/i <<" " << tmp << " " << ret << endl;
}
}
}
//if (now == 1 && prev == 12)cout << ret <<" " << prev << endl;
//if (now == 0 && prev == 12)cout << ret <<" " << prev << endl;
if (now < n-2)return M[now][prev]=ret;
else return ret;
return M[now][prev]=ret;
}
int main(){
int n;
while(cin>>n){
int in[n];
rep(i,n)cin>>in[i];
rep(i,n)M[i].clear();
sort(in,in+n);
double ans=solve(n,n-1,-1,in);
printf("%.12lf\n",ans);
#ifdef DEBUG
cout << "end " << endl;
#endif
}
return false;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount
#define INF INT_MAX/3
int n;
int a[22];
int c[22],d[22];
bool dp[20][200010];
bool ok(double x){
rep(i,n){
c[i]=(int)ceil((1.0-x)*(double)a[i]);
d[i]=(int)floor((1.0+x)*(double)a[i]);
}
memset(dp,0,sizeof(dp));
repl(i,c[0],d[0]+1)dp[0][i]=true;
rep(i,n-1){
repl(j,c[i],d[i]+1){
if(!dp[i][j])continue;
for(int k=1;j*k<=d[i+1];k++)dp[i+1][j*k]=true;
}
}
bool ok=false;
repl(i,c[n-1],d[n-1]+1){
if(dp[n-1][i])ok=true;
}
return ok;
}
int main(){
cin.sync_with_stdio(false);
cin>>n;
rep(i,n)cin>>a[i];
double lb=0.0,ub=1.0;
rep(hoge,30){
double mid=(lb+ub)/2.0;
if(ok(mid))ub=mid;
else lb=mid;
}
printf("%.12f\n", (lb+ub)/2.0);
return 0;
} |
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
for(T& x: v){ is >> x; } return is;
}
double getRate(double a, double b){
return abs(a - b) / a;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
cin >> a;
vector<vector<double>> dp(n, vector<double>(200000, numeric_limits<double>::max()));
rep(i,n){
range(j,1,200000){
if(i == 0){
dp[i][j] = getRate(a[i], j);
}else{
for(int k = j; k < 200000; k+=j){
dp[i][k] = min(dp[i][k], max(dp[i - 1][j], getRate(a[i], k)));
}
}
}
}
cout << fixed << setprecision(10) << *min_element(all(dp[n - 1])) << endl;
}
|
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long double ld;
const ld INF = 1e+8;
int main() {
int n;
cin>>n;
vector<int> a(n);
REP(i,n)cin>>a[n-i-1];
vector<ld> dp(200000,INF);
REP(i,200000) {
if(!i) continue;
dp[i] = abs((ld)(i-a[0]))/a[0];
}
REP(i,n-1) {
vector<ld> tmp(200000,INF);
REP(j,200000) {
if(!j) continue;
for(int k=j; k < 200000; k += j) {
tmp[j] = min(tmp[j], max(abs((ld)(j-a[i+1]))/a[i+1], dp[k]));
}
}
swap(tmp,dp);
}
cout << setprecision(10) << fixed << *min_element(begin(dp),end(dp)) << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
long double dp[21][201000];
ll N;
ll a[20];
void update(int idx) {
for(int before = 1; before <= 2e5; before++) {
for(int after = before; after <= 2e5; after += before) {
long double delta = abs(after - a[idx]);
chmin(dp[idx+1][after], max(dp[idx][before], delta / a[idx]));
}
}
}
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
for(int i = 0; i < N; i++) cin >> a[i];
for(int i = 0; i <= N; i++) {
for(int j = 0; j <= 2e5; j++) {
dp[i][j] = 1e8;
}
}
dp[0][1] = 0;
for(int i = 0; i < N; i++) {
update(i);
//for(int j = 1; j <= 30; j++) cerr << dp[i+1][j] << " ";
//cerr << endl;
}
long double ans = 1e18;
for(int i = 1; i <= 2e5; i++) {
chmin(ans, dp[N][i]);
}
cout << fixed << setprecision(30) << ans << endl;
return 0;
}
|
//19
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
int n;
cin>>n;
int a[20];
for(int i=0;i<n;i++){
cin>>a[i];
}
static double dp[2][200000];
fill(dp[0],dp[2],1<<30);
dp[0][1]=0;
for(int i=1;i<=n;i++){
fill(dp[i&1],dp[(i&1)+1],1<<30);
for(int j=1;j<200000;j++){
for(int k=j;k<200000;k+=j){
dp[i&1][k]=min(dp[i&1][k],max(dp[i-1&1][j],abs(k-a[i-1])*1./a[i-1]));
}
}
}
cout.precision(8);
cout<<fixed<<*min_element(dp[n&1],dp[(n&1)+1])<<endl;
return 0;
} |
#include<bits/stdc++.h>
/*
*/
using namespace std;
int main() {
int N;
cin >> N;
vector<int>D( N );
for( size_t i = 0; i < N; i++ ) {
cin >> D[i];
}
double maxans = 1, minans = 0;
for( size_t idx = 0; idx < 50; idx++ ) {
double midans = ( maxans + minans ) / 2;
set<int>prev;
prev.insert( 1 );
for( size_t i = 0; i < N; i++ ) {
double minvalue = D[i] * ( 1. - midans );
double maxvalue = D[i] * ( 1. + midans );
set<int>next;
for( auto one : prev ) {
for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
next.insert( j*one );
}
}
prev = next;
}
if( prev.size() ) {
maxans = midans;
} else {
minans = midans;
}
}
cout << fixed << setprecision( 20 ) << minans << endl;
} |
#include <cstdio>
#include <cstring>
inline int gcd(int a, int b) {
while (a != 0) {
int t = b % a;
b = a;
a = t;
}
return b;
}
inline int abs(int x) {
return x < 0 ? -x : x;
}
struct Frac {
int a, b;
Frac() : a(1), b(1) {}
Frac(int a, int b) : a(a), b(b) {
reduce();
}
void reduce() {
int g = gcd(a, b);
a /= g;
b /= g;
}
bool operator < (const Frac& f) const {
return (long long)a * f.b < (long long)b * f.a;
}
};
inline void checkMin(Frac& ret, const Frac& val) {
if (val < ret) {
ret = val;
}
}
inline void checkMax(Frac& ret, const Frac& val) {
if (ret < val) {
ret = val;
}
}
int n;
int a[100000];
Frac dp[2][200001];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= a[0] * 2; ++i) {
dp[0][i] = Frac(0, 1);
}
for (int i = 0; i < n; ++i) {
int lim = i + 1 == n ? 0 : a[i + 1] * 2;
for (int j = 1; j <= a[i] * 2; ++j) {
checkMax(dp[i % 2][j], Frac(abs(j - a[i]), a[i]));
for (int k = j; k <= lim; k += j) {
checkMin(dp[1 - i % 2][k], dp[i % 2][j]);
}
}
}
Frac res;
for (int i = 1; i <= a[n - 1] * 2; ++i) {
checkMin(res, dp[(n - 1) % 2][i]);
}
printf("%.13lf\n", (double)res.a / res.b);
return 0;
} |
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
int idx, val;
double score;
S(int i, int v, double s) :
idx(i), val(v), score(s) {}
bool operator < (const S& st) const {
if(score != st.score) return score > st.score;
if(idx != st.idx) return idx < st.idx;
return val > st.val;
}
};
int main(){
int N;
while(cin>>N && N){
int a[20];
REP(i, N) cin>>a[i];
priority_queue<S> que;
FOR(v, 1, 100001) que.push(S(1, v, (double)abs(a[0] - v) / a[0]));
bool used[20][150001] = {};
while(!que.empty()){
S s = que.top(); que.pop();
if(s.idx == N){
printf("%.12f\n", s.score);
break;
}
if(used[s.idx][s.val]) continue;
used[s.idx][s.val] = true;
for(int k = 1; k * s.val <= 150000; k++){
int nv = k * s.val;
que.push(S(s.idx + 1, nv, max(s.score, (double)abs(a[s.idx] - nv) / a[s.idx])));
}
}
}
return 0;
} |
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
int idx, val;
double score;
S(int i, int v, double s) :
idx(i), val(v), score(s) {}
bool operator < (const S& st) const {
if(score != st.score) return score > st.score;
if(idx != st.idx) return idx < st.idx;
return val > st.val;
}
};
int main(){
int N;
while(cin>>N && N){
int a[20];
REP(i, N) cin>>a[i];
priority_queue<S> que;
FOR(v, 1, 200001) que.push(S(1, v, (double)abs(a[0] - v) / a[0]));
while(!que.empty()){
S s = que.top(); que.pop();
if(s.idx == N){
printf("%.12f\n", s.score);
break;
}
for(int k = 1; k * s.val <= 200000; k++){
int nv = k * s.val;
que.push(S(s.idx + 1, nv, max(s.score, (double)abs(a[s.idx] - nv) / a[s.idx])));
}
}
}
return 0;
} |
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX = 200001;
double dp[20][MAX];
int main() {
int N;
cin >> N;
vector<int> a(N);
for(int i = 0; i < N; ++i) cin >> a[i];
for(int i = 0; i < N; ++i) {
for(int j = 0; j < MAX; ++j) dp[i][j] = -1;
}
for(int i = 0; i < N; ++i) {
for(int j = 1; j < MAX; ++j) {
dp[i][j] = max(dp[i][j], fabs(a[i]-j) / (double)a[i]);
//cout << i << ' ' << j << ' ' << dp[i][j] << endl;
if(i+1 < N) {
for(int k = j; k < MAX; k += j) {
if(dp[i+1][k] < 0 || dp[i+1][k] > dp[i][j]) {
dp[i+1][k] = dp[i][j];
}
}
for(int k = j; k >= 0; k -= j) {
if(dp[i+1][k] < 0 || dp[i+1][k] > dp[i][j]) {
dp[i+1][k] = dp[i][j];
}
}
}
}
}
double ans = 1e10;
for(int i = 1; i < MAX; ++i) {
ans = min(ans, dp[N-1][i]);
}
printf("%.8f\n", ans);
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long double ld;
ld dp[20][200010]={};
int main(){
int n;
cin >> n;
vector<ld>a(n);
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int i=0;i<20;i++){
for(int j=0;j<=200000;j++){
dp[i][j] = 100000.0000;
}
}
for(int i=1;i<=200000;i++){
dp[0][i] = abs(a[0]-(ld)i)/a[0];
}
for(int i=1;i<n;i++){
for(int j=1;j<=200000;j++){
for(int k=j;k<=200000;k+=j){
dp[i][k] = min(dp[i][k],max(abs(a[i]-(ld)k)/a[i],dp[i-1][j]));
}
}
}
ld mi = 100000000.0000;
for(int i=1;i<=200000;i++){
mi = min(dp[n-1][i],mi);
}
cout << fixed << setprecision(15) << mi << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 21
#define MAX_M 150001
#define INF (1<<29)
typedef long long ll;
double dp[MAX_N][MAX_M];
int main()
{
int N;
cin >> N;
vector<double> v(N);
for (int i = 0; i < N; i++) {
cin >> v[i];
}
fill(dp[0], dp[MAX_N], INF);
dp[0][1] = 0;
for (int i = 0; i < N; i++) {
for (int j = MAX_M-1; j >= 0; j--) {
if (dp[i][j] == INF) continue;
for (int k = 1; k <= MAX_M; k++) {
ll nv = (ll)j * k;
if (nv >= MAX_M) break;
dp[i+1][nv] = min(dp[i+1][nv],
max(dp[i][j], abs(v[i]-nv) / v[i]));
}
}
}
double res = INF;
for (int i = 0; i < MAX_M; i++) {
res = min(res, dp[N][i]);
}
printf("%.15f\n", res);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const int SIZE=2*1e5+1;
using dbl=double;
const dbl INF=2;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
vector<vector<dbl>> dp(n+1,vector<dbl>(SIZE,INF));
dp[0][1]=0;
for(int i=0;i<n;i++){
for(int j=1;j<SIZE;j++){
for(int k=j;k<SIZE;k+=j){
dp[i+1][k]=min(dp[i+1][k],max(dp[i][j],dbl(abs(a[i]-k))/a[i]));
}
}
}
cout<<fixed<<setprecision(10);
cout<<*min_element(dp[n].begin(),dp[n].end())<<endl;
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
int n,a[20];
double dp[21][200000],inf=1e10;
int main(){
cin>>n;
rep(i,n)cin>>a[i];
rep(i,n+1) rep(j,200000) dp[i][j]=inf;
dp[0][1]=0;
rep(i,n){
rep1(j,200000-1){
for(int k=1;k*j<200000;k++){
double dif=abs((double)(a[i]-k*j)/a[i]);
dp[i+1][k*j]=min(dp[i+1][k*j],max(dp[i][j],dif));
}
}
}
double ans=inf;
rep(j,200000) ans=min(ans,dp[n][j]);
printf("%.10f\n",ans);
} |
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef vector<double> vd;
typedef vector<vd> vvd;
int main(){
cout.precision(30);
int n;
cin>>n;
vi a(n);
REP(i,n){
cin>>a[i];
}
const int MAX=200000;
vvd dp(n,vd(MAX+1,INT_MAX));
REP(i,MAX+1){
dp[0][i]=(double)abs(i-a[0])/a[0];
}
REP(i,n-1){
FOR(j,1,MAX+1){
for(int k=1;k<=MAX&&j*k<=MAX;k++){
double confusion=(double)abs(j*k-a[i+1])/a[i+1];
dp[i+1][j*k]=min(dp[i+1][j*k],max(dp[i][j],confusion));
}
}
}
double ans=INT_MAX;
REP(i,MAX){
ans=min(ans,dp[n-1][i]);
}
cout<<ans<<endl;
} |
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
#define all(c) begin(c), end(c)
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;
using pii = pair<int, int>;
#define VV(T) vector<vector< T > >
int n;
int a[25];
double dp[25][252525];
double inf = 1e9;
double solve() {
fill((double*)begin(dp), (double*)end(dp), inf);
dp[0][1] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j < 252525; ++j) {
for (int k = j; k < 252525; k += j) {
double nxt = dp[i][j];
nxt = max(nxt, abs((double)(a[i] - k) / a[i]));
dp[i + 1][k] = min(dp[i + 1][k], nxt);
}
}
}
return *min_element(begin(dp[n]), end(dp[n]));
}
int main() {
while (cin >> n) {
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
printf("%.10lf\n", solve());
}
} |
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
int n;
int current[30];
double memo[20][200020];
double calc(int depth, int prev) {
if (depth == n) { return 0.0; }
if (!isnan(memo[depth][prev])) { return memo[depth][prev]; }
double ret = 1e+100;
int nv = prev;
while (nv <= 200010) {
ret = min(ret, max(calc(depth + 1, nv), (double)abs(current[depth] - nv) / current[depth]));
nv += prev;
}
return memo[depth][prev] = ret;
}
int main() {
while (scanf("%d", &n) > 0) {
MEMSET(memo, -1);
REP(i, n) {
scanf("%d", ¤t[i]);
}
sort(current, current + n);
double ans = 1e+100;
FOREQ(i, 1, 200010) {
ans = min(ans, calc(0, i));
}
printf("%.9f\n", ans);
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;
const int MAX_V = 200002;
int a[22];
int N;
double memo[22][MAX_V];
bool visited[22][MAX_V];
double dfs(int pos, int prev){
if(pos == N) return 0;
if(visited[pos][prev]) return memo[pos][prev];
double ret = 1e18;
for(int i=1;prev*i<MAX_V;i++){
int next = i * prev;
ret = min(ret, max(abs(a[pos]-next) / double(a[pos]), dfs(pos+1, next)));
}
visited[pos][prev] = true;
memo[pos][prev] = ret;
return ret;
}
int main(){
cin >> N;
for(int i=0;i<N;i++){
cin >> a[i];
}
printf("%.10f\n", dfs(0, 1));
return 0;
} |
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;
int main(){
ll n;
cin>>n;
vector<ll> a(n);
for(auto &i:a){cin>>i;}
ll mx=200001;
vector<vector<double>> dp(n,vector<double>(mx,E));
for(int i=1;i<mx;i++){
dp[0][i]=(double)abs(a[0]-i)/a[0];
}
for(int i=0;i+1<n;i++){
for(ll t=1;t<mx;t++){
for(ll h=1;t*h<mx;h++){
dp[i+1][t*h]=min(dp[i+1][t*h],max(dp[i][t],(double)abs(a[i+1]-t*h)/a[i+1]));
}
}
}
double ans=E;
for(auto &i:dp.back()){ans=min(ans,i);}
cout<<fixed<<setprecision(12)<<ans<<endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2305>
問題文============================================================
=================================================================
解説=============================================================
================================================================
*/
typedef long double ld;
ld solve(){
ld res = 0;
int N; cin >> N;
vector<ll> a(N); for(auto& in:a) cin >> in;
ll MAXA = *a.rbegin();
vector<vector<ld>> dp(N+1,vector<ld>(2*MAXA+1,INF));
vector<vector<ll>> Next(2*MAXA+1);
for(int i = 1; i <= 2*MAXA;i++){
for(int j = i; j <= 2*MAXA;j+=i){
Next[i].push_back(j);
}
}
for(int i = 1; i <= 2*MAXA;i++) dp[0][i] = 0; //abs(i-a[0])/(ld)a[0];
for(int i = 0; i < N;i++){
for(int j = 1; j <= 2*MAXA;j++){
for(int k = 0; k < Next[j].size(); k++){
dp[i+1][Next[j][k]] = min(dp[i+1][Next[j][k]],
max(dp[i][j],abs(Next[j][k]-a[i])/(ld)a[i]));
}
}
}
res = *min_element(dp[N].begin(), dp[N].end());
return res;
}
int main(void) {
cin.tie(0); ios_base::sync_with_stdio(false);
cout << fixed << setprecision(12) << solve() << endl;
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<ctype.h>
#include<queue>
#include<bitset>
#include<deque>
#include<set>
#include<time.h>
#include<math.h>
#include<sstream>
#include<functional>
#include<stack>
#include<map>
#include<vector>
using namespace std;
#define LL long long
#define MAXN 200000
int f[21];
double dp[29][400009];
double deal(int p,int val){
double rs=1.0;
for(int i=1;(i*val) <= (MAXN);i++){
rs = min(rs,dp[p+1][i*val]);
}
return rs;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
cin >> f[i];
sort(f,f+n);
for(int i=0;i<=n;i++)
for(int j=1;j<=MAXN;j++)
dp[i][j]=1.0;
for(int i=1;i<=MAXN;i++)
dp[n-1][i]=1.0*abs(f[n-1]-i)/f[n-1];
for(int i=n-2;i>=0;i--){
for(int j=1;j<=MAXN;j++){
dp[i][j]=max(deal(i,j), 1.0*abs(f[i]-j)/f[i]);
}
}
double ans = 1.0;
for(int i=1;i<=MAXN;i++){
ans = min(dp[0][i],ans);
}
printf("%.19lf\n",ans);
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a[25],n;
double dp[25][200005];
int main(){
cin >> n ; for(int i=1;i<=n;i++) cin >> a[i];
rep(j,25) rep(i,200005) dp[j][i] = 1e9;
dp[0][1] = 0;
double ans = 1e9;
for(int i=1;i<=n;i++){
for(int j=1;j<200005;j++){
for(int k=j;k<200005;k+=j){
if(dp[i-1][j] < 1e8){
dp[i][k] = min(dp[i][k],max(dp[i-1][j],(double)(abs(k-a[i]))/(double)(a[i])));
if(i==n) ans = min(ans,dp[i][k]);
}
}
}
}
printf("%.12f\n",ans);
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif
typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;
const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
void solve(){
int n;
cin >> n;
vector<int> a(n);
rep(i,0,n) cin >> a[i];
int maxi=2*1e5;
vector<long double> curr(maxi,infll),next(maxi,infll);
rep(i,1,maxi) curr[i]=(long double)(abs(a[0]-i))/a[0];
rep(i,0,n-1){
rep(j,1,maxi){
for(int k=j; k<maxi; k+=j){
next[k]=min(next[k],max(curr[j],(long double)(abs(a[i+1]-k))/a[i+1]));
}
}
swap(curr,next);
fill(next.begin(),next.end(),infll);
}
cout << *min_element(curr.begin(),curr.end()) << endl;
}
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(12);
solve();
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int n;
int t[20];
double dp[20][200001];
double calc(int a,int b){
int c=max(a-b,b-a);
return (double)c/(double)a;
}
int main(){
for(int i=0;i<20;i++)
for(int j=0;j<200001;j++)
dp[i][j]=1e9;
cin>>n;
for(int i=0;i<n;i++)cin>>t[i];
for(int j=1;j<=200000;j++)dp[0][j]=calc(t[0],j);
for(int i=0;i+1<n;i++){
for(int j=1;j<=200000;j++){
if(dp[i][j]==1e9)continue;
for(int k=j;k<=200000;k+=j){
dp[i+1][k]=min(dp[i+1][k],max(dp[i][j],calc(t[i+1],k)));
}
}
}
double ans=1e9;
for(int i=1;i<=200000;i++)
ans=min(ans,dp[n-1][i]);
printf("%.10f\n",ans);
return 0;
} |
// template {{{
#include <bits/stdc++.h>
using namespace std;
#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(c) std::begin(c), std::end(c)
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second
#define popcnt __builtin_popcountll
using uint = std::uint32_t;
using ll = std::int64_t;
using ull = std::uint64_t;
using ld = long double;
template<typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};
template<typename T>
inline T sq(T x){ return x * x; }
template<typename T, typename U>
inline bool chmax(T &x, U y){ if (x >= y) return false; x = y; return true; }
template<typename T, typename U>
inline bool chmin(T &x, U y){ if (x <= y) return false; x = y; return true; }
template<typename T>
inline void sort(T &c){ std::sort(all(c)); }
template<typename T>
inline void reverse(T &c){ std::reverse(all(c)); }
template<typename T>
inline void unique(T &c){ std::sort(c); c.erase(std::unique(all(c)), std::end(c)); }
// }}}
vector<int> ds[200010];
int n;
int a[21];
double dp[21][200010];
int main()
{
rep(i, 200010){
for (int j = 1; j * j <= i; j++){
if (i % j == 0){
ds[i].pb(j);
ds[i].pb(i / j);
}
}
}
cin >> n;
loop(i, 1, n + 1) cin >> a[i];
fill_n(*dp, 21 * 200010, 1e18);
dp[0][1] = 0.0;
loop(i, 1, n + 1) rep(j, 200010){
double c = (double)abs(a[i] - j) / a[i];
for (int d : ds[j]){
chmin(dp[i][j], max(dp[i - 1][d], c));
}
}
double res = 1e18;
rep(i, 200010) chmin(res, dp[n][i]);
printf("%.20lf\n", res);
} |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <time.h>
using namespace std;
typedef long long lint ;
#define N 150010
vector<int> v[N] ;
void get_ans(){
for(lint i = 1 ; i < N ; i++){
v[i].clear() ;
}
for(lint i = 1 ; i < N ; i++){
for(lint j = 1 ; j < N ; j++){
if(i*j > N) break ;
lint tag = i*j ;
v[tag].push_back(i) ;
}
}
}
double f[2][150001];
double a[21];
int main(){
int n;
get_ans();
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%lf",&a[i]);
}
for (int i=0;i<=1;i++)
for (int j=1;j<=150000;j++)
f[i][j]=1000000000;
for (int i=1;i<=150000;i++){
f[0][i]=abs(a[1]-i)/a[1];
}
int gd=0;
for (int i=2;i<=n;i++){
gd=1-gd;
for (int j=1;j<=150000;j++){
f[gd][j]=1000000000;
for (int k=0;k<v[j].size();k++){
int kk=v[j][k];
f[gd][j]=min(f[gd][j],max(f[1-gd][kk],abs(a[i]-j)/a[i]));
}
}
}
double ans=1000000000;
for (int j=1;j<=150000;j++){
ans=min(ans,f[gd][j]);
}
printf("%0.10lf\n",ans);
} |
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;
int main(){
int N;
scanf("%d",&N);
int* table = new int[N+1];
for(int i = 1; i <= N; i++)scanf("%d",&table[i]);
double** dp = new double*[N+1];
for(int i = 1; i <= N; i++){
dp[i] = new double[200000];
for(int k = 0; k < 200000; k++)dp[i][k] = 1.0;
}
double ans = 1.0;
for(int i = 1; i < 2*table[1]; i++)dp[1][i] = (double)(abs(i-table[1])/(double)table[1]);
for(int i = 1; i < N; i++){
for(int k = 1; k < 2*table[i]; k++){
for(int a = 1; k*a < 2*table[i+1];a++){
dp[i+1][k*a] = min(dp[i+1][k*a],max(dp[i][k],(double)(abs(k*a-table[i+1])/(double)table[i+1])));
}
}
}
for(int i = 1; i < 2*table[N];i++)ans = min(ans,dp[N][i]);
printf("%.12lf\n",ans);
return 0;
} |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
int main(){
int n;
cin>>n;
vector<int> v(n);
rep(i,n)cin>>v[i];
static double dp[21][130011];
rep(i,21)rep(j,130011)dp[i][j] = INF;
dp[0][1] = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=130010;j++){
for(int k=1;k<=sqrt(j);k++){
if(j%k==0){
dp[i][j] = min( dp[i][j], max( dp[i-1][k], (double)abs(v[i-1]-j)/v[i-1] ) );
dp[i][j] = min( dp[i][j], max( dp[i-1][j/k], (double)abs(v[i-1]-j)/v[i-1] ) );
}
}
}
}
double ans = INF;
rep(i,130011){
ans = min(ans,dp[n][i]);
}
printf("%.20lf\n",ans);
} |
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
#define all(c) begin(c), end(c)
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;
using pii = pair<int, int>;
#define VV(T) vector<vector< T > >
int n;
int a[25];
double dp[25][150000];
double inf = 1e9;
int main() {
while (cin >> n) {
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
fill((double*)begin(dp), (double*)end(dp), inf);
dp[0][1] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j < 150000; ++j) {
for (int k = j; k < 150000; k += j) {
double nxt = dp[i][j];
nxt = max(nxt, abs((double)(a[i] - k) / a[i]));
dp[i + 1][k] = min(dp[i + 1][k], nxt);
}
}
}
printf("%.10lf\n", *min_element(begin(dp[n]), end(dp[n])));
}
} |
#include <stdio.h>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int a[20];
int n;
bool DFS(int k, int m, double r){
int s=ceil(a[k]*(1-r));
if(s==0)s=1;
int e=ceil(a[k]*(1+r));
for(int p=((s-1)/m+1)*m;p<e;p+=m)
if(k==n-1)return true;
else if(DFS(k+1,p,r))return true;
return false;
}
int main(){
scanf("%d",&n);
REP(i,n)scanf("%d",a+i);
double u=1.0, l=0.0;
REP(i,30){
double m=(u+l)*0.5;
if(DFS(0,1,m))u=m;
else l=m;
}
printf("%.9f\n",u);
return 0;
} |
#include<bits/stdc++.h>
/*
*/
using namespace std;
int main() {
int N;
cin >> N;
vector<int>D( N );
for( size_t i = 0; i < N; i++ ) {
cin >> D[i];
}
double maxans = 1, minans = 0;
for( size_t idx = 0; idx < 27; idx++ ) {
double midans = ( maxans + minans ) / 2;
set<int>prev;
prev.insert( 1 );
for( size_t i = 0; i < N; i++ ) {
double minvalue = D[i] * ( 1. - midans );
double maxvalue = D[i] * ( 1. + midans );
set<int>next;
for( auto one : prev ) {
for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
next.insert( j*one );
}
}
prev = next;
}
if( prev.size() ) {
maxans = midans;
} else {
minans = midans;
}
}
cout << fixed << setprecision( 20 ) << minans << endl;
} |
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
double DP[200001], DP2[200001];
int main(){
int N;
cin >> N;
for(int i = 0; i < N; i++){
double num;
cin >> num;
for(int j = 0; j <= 200000; j++){
DP2[j] = INF;
}
for(int j = 1; j <= 200000; j++){
for(int k = j; k <= 200000; k += j){
DP2[k] = min(DP2[k], max(DP[j], abs(num - j) / num));
}
}
swap(DP, DP2);
}
double ans = INF;
for(int i = 1; i <= 200000; i++){
ans = min(ans, DP[i]);
}
printf("%.10f\n", ans);
return 0;
}
|
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
typedef long long ll;
typedef double D;
ll n,a[20];
D dp[21][200001];
const D INF = 1e12;
int main(){
cin >> n;
for(int i=0;i<n;i++)cin >> a[i];
for(int i=0;i<=n;i++){
for(int j=0;j<=a[n-1]*2;j++)dp[i][j] = INF;
}
dp[0][1] = 0;
for(int i=0;i<n;i++){
for(int j=1;j<=a[n-1]*2;j++){
for(int k=j;k<=a[n-1]*2;k+=j){
dp[i+1][k] = min(dp[i+1][k],max(dp[i][j],abs((D)(k-a[i])/a[i])));
}
}
}
D ans = INF;
for(int i=0;i<=a[n-1]*2;i++)ans = min(ans,dp[n][i]);
cout << setprecision(10) << fixed << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}
typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;
const int inf = 1LL << 55;
const int mod = 1e9 + 7;
const int LIMIT = 200001;
double dp[22][LIMIT];
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int N;
cin >> N;
vector<double> a(N);
rep(i, N) cin >> a[i];
fill(dp[0], dp[22], 1e10);
reps(i, 1, LIMIT) dp[0][i] = fabs(a[0]-i)/a[0];
rep(i, N-1) {
reps(j, 1, LIMIT) {
for(int k = 1; k*j < LIMIT; k++) {
chmin(dp[i+1][k*j], max(dp[i][j], fabs(a[i+1]-k*j)/a[i+1]));
}
}
}
double ans = 1e10;
reps(i, 1, LIMIT) chmin(ans, dp[N-1][i]);
cout << ans << endl;
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
double dp[21][150001];
const double INF=(1LL<<50);
int a[21];
int n;
double dfs(int idx,int lastNum){
if(idx==-1)
return 0.0;
if(!EQ(INF,dp[idx][lastNum]))
return dp[idx][lastNum];
double minCost=INF;
if(idx==n-1)
for(int i = 1; i <= 150000; i++){
if(minCost<(double)abs(a[idx]-i)/a[idx])
continue;
minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
}
else{
// lastNumðèØéÅJÚ
for(int i = 1; i*i <= lastNum; i++){
if(lastNum%i==0){
minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
minCost=min(minCost,max(dfs(idx-1,(lastNum/i)),(double)abs(a[idx]-(lastNum/i))/a[idx]));
}
}
}
return dp[idx][lastNum]=minCost;
}
int main(){
for(int i = 0; i < 21; i++)
for(int j = 0; j < 150001; j++)
dp[i][j]=INF;
cin>>n;
for(int i = 0; i < n; i++) cin>>a[i];
double res=dfs(n-1,0);
printf("%.9f\n",res);
return 0;
} |
#include<iostream>
#include<vector>
#include<cmath>
#include<cfloat>
#include<algorithm>
using namespace std;
#define M 200000
int main()
{
int N;
cin>>N;
vector<double>a(N);
vector< vector<double> >dp(N,vector<double>(M,DBL_MAX));
for(int i=0;i<N;i++)cin>>a[i];
for(int j=1;j<M;j++)dp[0][j]=fabs(a[0]-j)/a[0];
for(int i=1;i<N;i++)for(int j=1;j<M;j++)for(int k=1;j*k<M;k++){
dp[i][j*k]=min(dp[i][j*k],max(dp[i-1][j],fabs(a[i]-j*k)/a[i]));
}
double ans=DBL_MAX;
for(int j=1;j<M;j++)ans=min(ans,dp[N-1][j]);
printf("%.9f\n",ans);
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef _WIN32
#define scanfll(x) scanf("%I64d", x)
#define printfll(x) printf("%I64d", x)
#else
#define scanfll(x) scanf("%lld", x)
#define printfll(x) printf("%lld", x)
#endif
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>;
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; }
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U> ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; }
void printbits(ll mask, ll n) { rep(i, n) { cout << !!(mask & (1ll << i)); } cout << endl; }
#define ldout fixed << setprecision(40)
static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;
int main(void) {
cin.tie(0); ios::sync_with_stdio(false);
ll n; cin >> n;
vector<double> a(n); rep(i, a.size()) cin >> a[i];
const ll maxn = 200010;
static double dp[25][maxn];
rep(i, 25) rep(j, maxn) {
dp[i][j] = INF;
}
rep(i, maxn) {
dp[1][i] = (double)abs(i - a[0]) / (double)a[0];
}
// rep(i, 20) { cout << dp[1][i] << " "; } cout << endl;
repi(i, 1, n) repi(j, 1, maxn) for (ll h = j; h < maxn; h += j) {
chmin(dp[i+1][h], max(dp[i][j], (double)abs(h - a[i]) / (double)a[i]));
// rep(j, 20) { cout << dp[i+1][j] << " "; } cout << endl;
}
double ret = INF;
int i = n;
repi(j, 1, maxn) {
chmin(ret, dp[i][j]);
}
cout << ldout << ret << endl;
return 0;
} |
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <complex>
using namespace std;
#define mod 1000000007
double result[21][200001];
int main()
{
int n;
cin >> n;
double a[21];
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 1; i <= 200000; i++){
result[n - 1][i] = abs(i + 0.0 - a[n - 1]) / a[n - 1];
}
for(int i = n - 2; i >= 0; i--){
for(int j = 1; j <= 200000; j++){
result[i][j] = mod + 0.0;
for(int k = j; k <= 200000; k += j){
result[i][j] = min(result[i][j], max(abs(j + 0.0 - a[i]) / a[i], result[i + 1][k]));
}
}
}
double ans = mod + 0.0;
for(int i = 1; i <= 200000; i++){
ans = min(ans, result[0][i]);
}
printf("%.10f\n", ans);
}
|
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
const double eps = 1e-9;
int N;
int a[20];
vector<double> v;
bool equals(double s, double t) {
return fabs(s-t) < eps;
}
bool rec(int bx, int k, double lim) {
if(k == N) return true;
for(int b = bx; ; b += bx) {
double newV = (double)abs(a[k]-b)/a[k];
if(newV < lim || equals(newV, lim)) {
if(rec(b, k+1, lim)) return true;
} else {
if(a[k] < b) break;
else continue;
}
}
return false;
}
double solve() {
v.push_back(0.0);
for(int m = 1; m <= 100000; ++m)
for(int i = 0; i < N; ++i)
v.push_back((double)m/a[i]);
sort(v.begin(), v.end());
int l = 0;
int r = v.size();
int ansi = 0;
while(l < r) {
int m = (l+r)/2;
if(rec(1, 0, v[m])) ansi = r = m;
else l = m+1;
}
return v[ansi];
}
int main() {
cin >> N;
for(int i = 0; i < N; ++i) cin >> a[i];
printf("%.12f\n", solve());
return 0;
} |
// Enjoy your stay.
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())
using namespace std;
typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;
int N,a[22],L[22],H[22];
int memo[200010];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>N;
rep(i,N)cin>>a[i];
double lo = 0, hi = 1;
rep(_,40){
double mi = (lo+hi)/2;
rep(i,N){
L[i] = ceil(a[i] * (1 - mi));
H[i] = floor(a[i] * (1 + mi));
}
vector<int> cur,nx;
rep2(i,L[0],H[0]+1){
cur.pb(i);
}
rep2(i,1,N){
if(sz(cur) == 0)break;
nx.clear();
memset(memo,0,sizeof(memo));
rep(j,sz(cur)){
for(int k = (L[i] + cur[j] - 1) / cur[j] * cur[j];
k <= H[i] / cur[j] * cur[j]; k += cur[j]){
if(!memo[k]){
nx.pb(k);
memo[k] = 1;
}
}
}
cur = nx;
}
if(sz(cur)>0) hi = mi;
else lo = mi;
}
cout<<fixed<<setprecision(16)<<hi<<endl;
} |
// Enjoy your stay.
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())
using namespace std;
typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;
int N,a[22];
double dp[22][200010];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>N;
rep(i,N)cin>>a[i];
rep(i,N+1)rep2(j,1,200001)dp[i][j] = i ? INF : 0;
rep(i,N)rep2(j,1,200001){
for(int k = j; k <= 200000; k += j){
dp[i+1][k] = min(dp[i+1][k], max(dp[i][j], fabs(a[i] - k)/a[i]));
}
}
double ans = INF;
rep2(j,1,200001)ans=min(ans,dp[N][j]);
cout<<fixed<<setprecision(16)<<ans<<endl;
} |
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<climits>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 300000
using namespace std;
double dp[20][MAX];
int N;
double input[20];
int main(){
cin >> N;
rep(i,N)cin >> input[i];
rep(i,N)rep(j,MAX)dp[i][j] = IINF;
rep(i,MAX){
dp[0][i] = abs(input[0]-i)/input[0];
}
rep(i,N-1){
REP(j,1,MAX){
if(dp[i][j] == IINF) continue;
for(int k=j;k<MAX;k+=j){
dp[i+1][k] = min(dp[i+1][k],
max(dp[i][j],abs(input[i+1]-k)/input[i+1]));
}
}
}
double ans = IINF;
rep(i,MAX){
ans = min(ans,dp[N-1][i]);
}
printf("%.12f\n",ans);
return 0;
} |
#include<bits/stdc++.h>
/*
*/
using namespace std;
int main() {
int N;
cin >> N;
vector<int>D( N );
for( size_t i = 0; i < N; i++ ) {
cin >> D[i];
}
double maxans = 1, minans = 0;
for( size_t idx = 0; idx < 28; idx++ ) {
double midans = ( maxans + minans ) / 2;
set<int>prev;
prev.insert( 1 );
for( size_t i = 0; i < N; i++ ) {
double minvalue = D[i] * ( 1. - midans );
double maxvalue = D[i] * ( 1. + midans );
set<int>next;
for( auto one : prev ) {
for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
next.insert( j*one );
}
}
prev = next;
}
if( prev.size() ) {
maxans = midans;
} else {
minans = midans;
}
}
cout << fixed << setprecision( 20 ) << minans << endl;
} |
#include<bits/stdc++.h>
/*
*/
using namespace std;
int main() {
int N;
cin >> N;
vector<int>D( N );
for( size_t i = 0; i < N; i++ ) {
cin >> D[i];
}
double maxans = 1, minans = 0;
for( size_t idx = 0; idx < 30; idx++ ) {
double midans = ( maxans + minans ) / 2;
set<int>prev;
prev.insert( 1 );
for( size_t i = 0; i < N; i++ ) {
double minvalue = D[i] * ( 1. - midans );
double maxvalue = D[i] * ( 1. + midans );
set<int>next;
for( auto one : prev ) {
for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
next.insert( j*one );
}
}
prev = next;
}
if( prev.size() ) {
maxans = midans;
} else {
minans = midans;
}
}
cout << fixed << setprecision( 20 ) << minans << endl;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)
double dp[21][200001];
const double INF=(1LL<<50);
int a[21];
int n;
double dfs(int idx,int lastNum){
if(idx==-1)
return 0.0;
if(!EQ(INF,dp[idx][lastNum]))
return dp[idx][lastNum];
double minCost=INF;
if(idx==n-1)
for(int i = 1; i <= 200000; i++){
minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
}
else
// lastNumðèØéÅJÚ
for(int i = 1; i*i <= lastNum; i++){
if(lastNum%i==0){
minCost=min(minCost,max(dfs(idx-1,i),(double)abs(a[idx]-i)/a[idx]));
minCost=min(minCost,max(dfs(idx-1,(lastNum/i)),(double)abs(a[idx]-(lastNum/i))/a[idx]));
}
}
return dp[idx][lastNum]=minCost;
}
int main(){
for(int i = 0; i < 21; i++)
for(int j = 0; j < 200001; j++)
dp[i][j]=INF;
cin>>n;
for(int i = 0; i < n; i++) cin>>a[i];
double res=dfs(n-1,0);
printf("%.9f\n",res);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
int main() {
cin.tie(0); ios::sync_with_stdio(false);
int N; cin >> N;
vector<double> a(N);
for(auto& d : a) cin >> d;
const int MAX = 150010;
vector<double> dp(MAX, 0), tmp;
rep(i, MAX) dp[i] = abs(a[0] - i) / a[0];
REP(i, 1, N) {
tmp.assign(MAX, 1.0e9);
const int ub = (int)(1.5 * a[i] + 1.0);
REP(k, 1, ub)
for(int j = 1; k * j < ub; ++j) {
double upd = max(dp[k] , abs(a[i] - k * j) / a[i]);
tmp[k * j] = min(tmp[k * j], upd);
}
dp.swap(tmp);
}
cout << fixed << setprecision(10) << *min_element(dp.begin(), dp.end()) << endl;
return 0;
} |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#include <complex>
#ifdef _MSC_VER
#include <agents.h>
#endif
#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 2e5 + 10;
vector<int> divisor[N];
double dp[25][N];
double a[25];
double rec(int i, int val){
if (i == 0) return abs(val - a[i]) / a[i];
double &res = dp[i][val];
if (res > -.5) return res;
res = 1e9;
for (auto d : divisor[val]){
res = min(res, rec(i - 1, val / d));
}
res = max(res, abs(val - a[i]) / a[i]);
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
FOR(i, 1, N) for (int j = i; j < N; j += i) divisor[j].push_back(i);
int n;
cin >> n;
rep(i, n) cin >> a[i];
rep(i, 25) rep(j, N) dp[i][j] = -1;
double ans = 1e9;
FOR(i, 1, N){
//cout << i << ' ' << rec(n - 1, 36) << endl;
ans = min(ans, rec(n - 1, i));
}
cout.setf(ios::fixed);
cout.precision(12);
cout << ans << endl;
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
double dp[21][200001];
int v[20];
int main(){
int n;
cin >> n;
for(int i = 0 ; i < n ; i++) cin >> v[i];
for(int i = 0 ; i < 21 ; i++)
for(int j = 0 ; j <= 200000 ; j++)
dp[i][j] = 1e10;
dp[0][1] = 0;
for(int i = 0 ; i < n ; i++){
for(int j = 1 ; j <= 200000 ; j++){
if(dp[i][j] != 1e10){
for(int k = j ; k <= 200000 ; k+=j){
dp[i+1][k] = min(dp[i+1][k],max(dp[i][j],fabs(v[i]-k)/v[i]));
}
}
}
}
printf("%.10f\n",*min_element(dp[n],dp[n]+200001));
} |
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int N;
int val[20];
const double INF = 1e30;
const int lim = 200005;
double dp[200005][2];
double solve()
{
for(int j=0; j<2; j++)
for(int i=0; i<lim; i++)
dp[i][j] = INF;
for(int i=1; i<lim; i++)
dp[i][0] = 1.0*abs(i-val[0]) / val[0];
for(int i=1; i<N; i++)
{
for(int j=1; j<lim; j++)
dp[j][i%2] = INF;
for(int j=1; j<lim; j++)
{
if(dp[j][(i+1)%2]==INF) continue;
for(int k=1; j*k<lim; k++)
dp[j*k][i%2] = min(dp[j*k][i%2], max(dp[j][(i+1)%2], 1.0*abs(j*k-val[i])/val[i]));
}
}
double res = INF;
for(int i=1; i<lim; i++)
res = min(res, dp[i][(N+1)%2]);
return res;
}
int main()
{
cin >> N;
for(int i=0; i<N; i++)
cin >> val[i];
cout.setf(ios::fixed);
cout.precision(10);
cout << solve() << endl;
} |
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include <math.h>
#include<algorithm>
// #include <boost/multiprecision/cpp_int.hpp>
#include<functional>
#define int long long
#define inf 1000000007
#define pa pair<int,int>
#define ll long long
#define pal pair<double,double>
#define ppap pair<pa,int>
#define ssa pair<string,int>
#define mp make_pair
#define pb push_back
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
using namespace std;
class pa3{
public:
int x,y,z;
pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
bool operator < (const pa3 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
return z<p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa3 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
return z>p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa3 &p) const{
return x==p.x && y==p.y && z==p.z;
}
bool operator != (const pa3 &p) const{
return !( x==p.x && y==p.y && z==p.z);
}
};
class pa4{
public:
double x;
int y,z,w;
pa4(double x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
bool operator < (const pa4 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
if(z!=p.z)return z<p.z;
return w<p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa4 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
if(z!=p.z)return z>p.z;
return w>p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa4 &p) const{
return x==p.x && y==p.y && z==p.z &&w==p.w;
}
};
class pa2{
public:
int x,y;
pa2(int x=0,int y=0):x(x),y(y) {}
pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
bool operator < (const pa2 &p) const{
return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa2 &p) const{
return abs(x-p.x)==0 && abs(y-p.y)==0;
}
bool operator != (const pa2 &p) const{
return !(abs(x-p.x)==0 && abs(y-p.y)==0);
}
};
#define ppa pair<int,pas>
class Point{
public:
double x,y;
Point(double x=0,double y=0):x(x),y(y) {}
Point operator + (Point p) {return Point(x+p.x,y+p.y);}
Point operator - (Point p) {return Point(x-p.x,y-p.y);}
Point operator * (double a) {return Point(x*a,y*a);}
Point operator / (double a) {return Point(x/a,y/a);}
double absv() {return sqrt(norm());}
double norm() {return x*x+y*y;}
bool operator < (const Point &p) const{
return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const Point &p) const{
return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
}
};
typedef Point Vector;
#define pl pair<int,pas>
struct Segment{
Point p1,p2;
};
double dot(Vector a,Vector b){
return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
}
bool parareru(Point a,Point b,Point c,Point d){
// if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
return abs(cross(a-b,d-c))<EPS;
}
double distance_ls_p(Point a, Point b, Point c) {
if ( dot(b-a, c-a) < EPS ) return (c-a).absv();
if ( dot(a-b, c-b) < EPS ) return (c-b).absv();
return abs(cross(b-a, c-a)) / (b-a).absv();
}
bool is_intersected_ls(Segment a,Segment b) {
if(a.p1==b.p1||a.p2==b.p1||a.p1==b.p2||a.p2==b.p2) return false;
if(parareru((a.p2),(a.p1),(a.p1),(b.p2))&¶reru((a.p2),(a.p1),(a.p1),(b.p1))){
// cout<<"sss"<<endl;
if(dot(a.p1-b.p1,a.p1-b.p2)<EPS) return true;
if(dot(a.p2-b.p1,a.p2-b.p2)<EPS) return true;
if(dot(a.p1-b.p1,a.p2-b.p1)<EPS) return true;
if(dot(a.p1-b.p2,a.p2-b.p2)<EPS) return true;
return false;
}
else return ( cross(a.p2-a.p1, b.p1-a.p1) * cross(a.p2-a.p1, b.p2-a.p1) < EPS ) && ( cross(b.p2-b.p1, a.p1-b.p1) * cross(b.p2-b.p1, a.p2-b.p1) < EPS );
}
double segment_dis(Segment a,Segment b){
if(is_intersected_ls(a,b))return 0;
double r=distance_ls_p(a.p1, a.p2, b.p1);
r=min(r,distance_ls_p(a.p1, a.p2, b.p2));
r=min(r,distance_ls_p(b.p1, b.p2, a.p2));
r=min(r,distance_ls_p(b.p1, b.p2, a.p1));
return r;
}
Point intersection_ls(Segment a, Segment b) {
Point ba = b.p2-b.p1;
double d1 = abs(cross(ba, a.p1-b.p1));
double d2 = abs(cross(ba, a.p2-b.p1));
double t = d1 / (d1 + d2);
return a.p1 + (a.p2-a.p1) * t;
}
string itos( int i ) {
ostringstream s ;
s << i ;
return s.str() ;
}
int gcd(int v,int b){
if(v>b) return gcd(b,v);
if(v==b) return b;
if(b%v==0) return v;
return gcd(v,b%v);
}
double distans(double x1,double y1,double x2,double y2){
double rr=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
return sqrt(rr);
}
// int pr[2000010];
// int inv[2000010];
int beki(int wa,int rr,int warukazu){
if(rr==0) return 1ll;
if(rr==1) return wa%warukazu;
if(rr%2==1) return (beki(wa,rr-1,warukazu)*wa)%warukazu;
int zx=beki(wa,rr/2,warukazu);
return (zx*zx)%warukazu;
}
/*
int comb(int nn,int rr){
int r=pr[nn]*inv[rr];
r%=inf;
r*=inv[nn-rr];
r%=inf;
return r;
}
void gya(int ert){
pr[0]=1;
for(int i=1;i<ert;i++){
pr[i]=(pr[i-1]*i)%inf;
}
for(int i=0;i<ert;i++) inv[i]=beki(pr[i],inf-2,inf);
}
*/
//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
//sort(ve.begin(),ve.end(),greater<int>());
//----------------kokomade tenpure------------
//vector<double> ans(100000000),ans2(100000000);
vector<int> ve[200003];
double dp[25][200003]={0};
int a[30];
int n;
double dfs(int i,int j){
if(dp[i][j]>-0.001) return dp[i][j];
if(i==n){
dp[i][j]=abs(j-a[i]+0.0)/a[i]*1.0;
return dp[i][j];
}
double w=abs(j-a[i]+0.0)/a[i]*1.0;
double e=1000000;
for(auto v:ve[j]){
e=min(e,dfs(i+1,v));
}
dp[i][j]=max(w,e);
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
return dp[i][j];
}
signed main(){
for(int i=0;i<25;i++)for(int j=0;j<200003;j++)dp[i][j]=-100;
for(int i=1;i<=200000;i++){
int j=1;
while(j*j<=i){
if(j*j==i){
ve[i].pb(j);
break;
}
if(i%j==0){
ve[i].pb(j);
ve[i].pb(i/j);
}
j++;
}
sort(ve[i].begin(),ve[i].end());
}
cin>>n;
for(int i=0;i<n;i++){
cin>>a[n-i];
}
double ans=1000000000;
for(int i=1;i<=2*a[1];i++)ans=min(ans,dfs(1,i));
printf("%.10lf\n",ans);
return 0;
}
|
#include<bits/stdc++.h>
#define inf 1<<29
#define MAX 200010
using namespace std;
int n;
double dp[21][MAX],a[21];
int main()
{
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)for(int j=0;j<MAX;j++)dp[i][j]=inf;
for(int i=1;i<MAX;i++)dp[0][i]=abs(a[0]-i)/a[0];
for(int i=1;i<n;i++){
for(int j=1;j<MAX;j++){
for(int k=j;k<MAX;k+=j){
dp[i][k]=min(dp[i][k],max(dp[i-1][j],abs(a[i]-k)/a[i]));
}
}
}
double ans=inf;
for(int i=1;i<MAX;i++)ans=min(ans,dp[n-1][i]);
printf("%.10f\n",ans);
return 0;
} |
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define M (201000)
int N, a[40];
double dp[40][M];
inline double calc(double a, double b) { return fabs(a-b)/a; }
int main() {
scanf("%d", &N);
rep(i, N) scanf("%d", a+i);
rep(i, N) rep(j, M) dp[i][j] = 1e100;
rep(i, M) dp[0][i] = calc(a[0], i);
rep(i, N-1) for(int j=1; j<M; j++) for(int k=j; k<M; k+=j) {
dp[i+1][k] = min(dp[i+1][k], max(dp[i][j], calc(a[i+1], k)));
}
double ans = 1e100;
rep(i, M) ans = min(ans, dp[N-1][i]);
printf("%.12f\n", ans);
return 0;
} |
// Enjoy your stay.
#include <bits/stdc++.h>
#define ECH(it, A) for (__typeof((A).begin()) it=(A).begin(); it != (A).end(); ++it)
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())
using namespace std;
typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;
int N,a[22],L[22],H[22];
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>N;
rep(i,N)cin>>a[i];
double lo = 0, hi = 1;
rep(_,40){
double mi = (lo+hi)/2;
rep(i,N){
L[i] = ceil(a[i] * (1 - mi));
H[i] = floor(a[i] * (1 + mi));
}
set<int> cur,nx;
rep2(i,L[0],H[0]+1){
cur.insert(i);
}
rep2(i,1,N){
if(sz(cur) == 0)break;
nx.clear();
ECH(it, cur){
int t = *it;
for(int k = (L[i] + t - 1) / t * t;
k <= H[i] / t * t; k += t){
//if(!memo[k]){
nx.insert(k);
//memo[k] = 1;
//}
}
}
cur = nx;
}
if(sz(cur)) hi = mi;
else lo = mi;
}
cout<<fixed<<setprecision(16)<<hi<<endl;
} |
#include <iostream>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define inf 1e9
using namespace std;
int N;
int a[20];
vector<int> fact[200005];
double dp[20][200005];
int main(void)
{
cin >> N;
for(int i = 0; i < N; i++) cin >> a[i];
for(int i = 1; i <= 200000; i++){
for(int j = i; j <= 200000; j += i){
fact[j].push_back(i);
}
}
for(int i = 1; i <= 200000; i++){
dp[0][i] = fabs(a[0] - i) / a[0];
}
double r;
for(int i = 1; i < N; i++){
for(int j = 1; j <= 200000; j++){
r = inf;
for(int k = 0; k < fact[j].size(); k++) r = min(r, dp[i-1][fact[j][k]]);
dp[i][j] = max( r, fabs(a[i]-j) / a[i] );
}
}
int min_i; double min_val = inf;
for(int i = 1; i <= 200000; i++){
if(min_val > dp[N-1][i]){
min_val = dp[N-1][i];
min_i = i;
}
}
double ans = inf;
for(int i = 1; i <= 200000; i++) ans = min(ans, dp[N-1][i]);
printf("%.10f\n", ans);
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<climits>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 200000
using namespace std;
double dp[20][MAX];
int N;
double input[20];
int main(){
cin >> N;
rep(i,N)cin >> input[i];
rep(i,N)rep(j,MAX)dp[i][j] = IINF;
rep(i,MAX){
dp[0][i] = abs(input[0]-i)/input[0];
}
rep(i,N-1){
REP(j,1,MAX){
if(dp[i][j] == IINF) continue;
for(int k=j;k<MAX;k+=j){
dp[i+1][k] = min(dp[i+1][k],
max(dp[i][j],abs(input[i+1]-k)/input[i+1]));
}
}
}
double ans = IINF;
rep(i,MAX){
ans = min(ans,dp[N-1][i]);
}
printf("%.12f\n",ans);
return 0;
} |
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
const int mn = 200000;
ld dp[21][mn];
ld dist(ld a, ld b) {
return abs(b - a) / a;
}
int n;
void solve() {
vector<int> h(n); rep(i, n)cin >> h[i];
rep(i, n + 1) {
rep(j, mn) {
dp[i][j] = INF;
}
}
dp[0][1] = 0;
rep(i, n) {
rep1(j, mn - 1) {
for (int k = j; k < mn; k += j) {
ld c = dist(h[i], k);
dp[i + 1][k] = min(dp[i + 1][k], max(dp[i][j],c));
}
}
}
ld ans = INF;
rep(i, mn) {
ans = min(ans, dp[n][i]);
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(9);
while (cin >>n,n) {
solve(); break;
}
//stop
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;
typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)
#define INF 999999999
double dp[22][150002];
int main(void){
int n;
int t[22];
while(scanf("%d",&n) != EOF){
rep(i,n){
scanf("%d",&t[i]);
}
rep(i,22) rep(j,150002) dp[i][j] = INF;
REP(i,1,150002) dp[0][i] = (double)(abs(t[0] - i)) / t[0];
rep(i,n-1){
rep(j,150002){
if(dp[i][j] == INF) continue;
for(int k=j;k<150002;k+=j){
dp[i+1][k] = min(dp[i+1][k],max(dp[i][j],(double)(abs(t[i+1]-k))/t[i+1]));
}
}
}
double ans = INF;
rep(i,150002){
if(dp[n-1][i] == -1) continue;
ans = min(ans,dp[n-1][i]);
}
printf("%.10f\n",ans);
}
} |
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;
using ld = long double;
int main()
{
int N;
cin >> N;
vector<ll> a(N);
for (int i = 0; i < N; i++) { cin >> a[i]; }
constexpr int MAX = 200000;
constexpr ld INF = 1e100;
vector<ld> dp(MAX, INF);
dp[1] = 0;
for (int i = 0; i < N; i++) {
vector<ld> tmp(MAX, INF);
for (int j = 1; j < MAX; j++) {
if (dp[j] == INF) { continue; }
for (int k = j; k < MAX; k += j) { tmp[k] = min(tmp[k], max(dp[j], (ld)abs(k - a[i]) / a[i])); }
}
dp = tmp;
}
const ld ans = *min_element(dp.begin(), dp.end());
cout << fixed << setprecision(15) << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 21
#define MAX_M 200001
#define INF (1<<29)
typedef long long ll;
double dp[MAX_N][MAX_M];
int main()
{
int N;
cin >> N;
vector<double> v(N);
for (int i = 0; i < N; i++) {
cin >> v[i];
}
fill(dp[0], dp[MAX_N], INF);
dp[0][1] = 0;
for (int i = 0; i < N; i++) {
for (int j = MAX_M-1; j >= 0; j--) {
if (dp[i][j] == INF) continue;
for (int k = 1; k <= MAX_M; k++) {
ll nv = (ll)j * k;
if (nv >= MAX_M) break;
dp[i+1][nv] = min(dp[i+1][nv],
max(dp[i][j], abs(v[i]-nv) / v[i]));
}
}
}
double res = INF;
for (int i = 0; i < MAX_M; i++) {
res = min(res, dp[N][i]);
}
printf("%.15f\n", res);
return 0;
} |
#include<bits/stdc++.h>
/*
*/
using namespace std;
int main() {
int N;
cin >> N;
vector<int>D( N );
for( size_t i = 0; i < N; i++ ) {
cin >> D[i];
}
double maxans = 1, minans = 0;
for( size_t idx = 0; idx < 100; idx++ ) {
double midans = ( maxans + minans ) / 2;
set<int>prev;
prev.insert( 1 );
for( size_t i = 0; i < N; i++ ) {
double minvalue = D[i] * ( 1. - midans );
double maxvalue = D[i] * ( 1. + midans );
set<int>next;
for( auto one : prev ) {
for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
next.insert( j*one );
}
}
prev = next;
}
if( prev.size() ) {
maxans = midans;
} else {
minans = midans;
}
}
cout << fixed << setprecision( 20 ) << minans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int main() {
int n;
cin >> n;
int lim = 140000;
vector<double> dp(lim, 1e8);
dp[1] = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
vector<double> next(lim, 1e8);
for (int j = 1; j < lim; ++j)
for (int k = j; k < lim; k += j)
next[k] = min(next[k], max(dp[j], abs(a - k) / (double)a));
dp = next;
}
double ans = 1e8;
for (auto i : dp)
ans = min(ans, i);
printf("%.16lf\n", ans);
return 0;
} |
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
const int MX = 2e5;
int main() {
int n;
cin >> n;
int a[n];
rep (i, n) cin >> a[i];
double dp[2][MX];
rep (i, 2) rep (j, MX) dp[i][j] = 1e99;
dp[0][1] = 0;
rep (i, n) {
rep (j, MX) if (j > 0) for (int k = j; k < MX; k += j) dp[1][k] = min(dp[1][k], max(dp[0][j], (double)abs(k - a[i]) / a[i]));
rep (j, MX) dp[0][j] = dp[1][j];
rep (j, MX) dp[1][j] = 1e99;
}
double res = 1e99;
rep (i, MX) res = min(res, dp[0][i]);
printf("%.12lf\n", res);
} |
#include <bits/stdc++.h>
using namespace std;
#ifdef _WIN32
#define scanfll(x) scanf("%I64d", x)
#define printfll(x) printf("%I64d", x)
#else
#define scanfll(x) scanf("%lld", x)
#define printfll(x) printf("%lld", x)
#endif
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>;
using vi = vector<int>; using vvi = vector<vi>;
vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; }
using P = pair<ll, ll>;
template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; }
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; }
template <typename T, typename U> ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; }
void printbits(ll mask, ll n) { rep(i, n) { cout << !!(mask & (1ll << i)); } cout << endl; }
#define ldout fixed << setprecision(40)
static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;
int main(void) {
cin.tie(0); ios::sync_with_stdio(false);
ll n; cin >> n;
vector<double> a(n); rep(i, a.size()) cin >> a[i];
const ll maxn = 200010;
static double dp[25][maxn];
rep(i, 25) rep(j, maxn)
dp[i][j] = INF;
rep(i, maxn)
dp[1][i] = (double)abs(i - a[0]) / (double)a[0];
repi(i, 1, n) repi(j, 1, maxn) for (ll h = j; h < maxn; h += j)
chmin(dp[i+1][h], max(dp[i][j], (double)abs(h - a[i]) / (double)a[i]));
double ret = INF;
int i = n;
repi(j, 1, maxn)
chmin(ret, dp[i][j]);
cout << ldout << ret << endl;
return 0;
} |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
#define N 200001
double dp[N];
double tmp[N];
double func(double a) {
if (a<0) return -a;
return a;
}
int main() {
int n;
cin >> n;
int a[n];
for (int i=0; i<n; ++i) {
cin >> a[i];
}
for (int j=0;j<N; ++j) {
dp[j] = 1<<29;
}
vector<int> v[N];
for(int i=1; i<N; ++i) {
for (int j=i; j<N; j+=i) {
v[j].push_back(i);
}
}
dp[1] = 0;
for (int i=1; i<=n; ++i) {
for (int j=0; j<N; ++j)
tmp[j] = 1<<29;
for (int j=0;j<N; ++j) {
for (int k=0; k<v[j].size(); ++k) {
tmp[j] = min(tmp[j], max(dp[v[j][k]], func(a[i-1]-j)/a[i-1]));
}
// if (j<=12) {
// cout << dp[i][j];
// printf("(%d) ", j);
// }
}
for (int j=0; j<N; ++j)
dp[j] = tmp[j];
// cout << endl;
}
double ans = 1<<29;
for (int i=0; i<N; ++i) {
if (ans > dp[i]) {
// printf("%d %f\n", i, dp[n][i]);
ans = dp[i];
}
//ans = min(ans, dp[n][i]);
}
printf("%.12f\n", ans);
// printf("ans = %.12f\n", 5.0/99999);
// printf("ans = %.12f\n", 1.0/50002);
} |
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define VV(T) vector<vector< T > >
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t){
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x
#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
vector<double> dp(2*1e5);
void mainmain(){
int n;
cin>>n;
vector<double> a(n);
rep(i,n) cin>>a[i];
int m=2*1e5;
rep(i,m){
dp[i]=1e200;
}
// cout<<m<<endl;
rep(i,m){
dp[i]=(double)abs(a[0]-(double)i)/(double)a[0];
// if(i<20) cout<<i<<" "<<abs(a[0]-i)<<" "<<1.*dp[i]<<endl;
}
// cout<<endl;
reep(i,1,n){
vector<double> tmp(m,(double)1e200);
reep(j,1,m){
if(dp[j]==1e200) continue;
for(int k=j;k<m;k+=j){
tmp[k]=min(tmp[k],max(dp[j],abs((double)k-a[i])/a[i]));
}
}
tmp.swap(dp);
}
double ans=1e200;
rep(i,m){
ans=min(ans,dp[i]);
}
cout<<fixed<<setprecision(10)<<ans<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
mainmain();
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (auto& i : vec) cin >> i;
double l = 0., r = 1.0;
for (int c = 0; c < 27; c++) {
double m = (l + r) / 2.0;
set<int> s;
s.insert(1);
for (int i = 0; i < N; i++) {
int lo_n = ceil((1.0 - m) * (double)vec[i]);
int up_n = (1.0 + m) * vec[i];
set<int> ns;
for (auto j : s) {
int v = up_n / j;
int u = ceil((double)lo_n / j);
for (; u <= v; u++) if (u != 0) ns.insert(j * u);
}
s = ns;
}
if (s.size() > 0) r = m;
else l = m;
}
printf("%.10f\n", l);
return 0;
} |
#include <bits/stdc++.h>
#define N 30
#define M 200000
using namespace std;
int n,A[N];
double calc(double a,double b){return abs(a-b)/a;}
double dp[2][M];
double DP(){
bool f=0;
for(int i=0;i<M;i++) dp[0][i] = 1LL<<50;
dp[0][1] = 0;
for(int i=0;i<n;i++,f=!f){
for(int j=0;j<M;j++) dp[!f][j] = 1LL<<50;
for(int num=1;num<M;num++)
for(int j=num;j<M;j+=num)
dp[!f][j] = min(dp[!f][j],max(calc(A[i],j),dp[f][num]));
}
double res=1LL<<55;
for(int i=0;i<M;i++) res=min(res,dp[f][i]);
return res;
}
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>A[i];
printf("%.10f\n",DP());
return 0;
} |
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int M=200001;
int n;
vd a;
int main(){
cin>>n;
a=vd(n);
vd dp(M);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=1;i<M;i++) dp[i]=fabs(a[0]-i)/a[0];
for(int i=1;i<n;i++){
vd DP(M,inf);
for(int j=1;j<M;j++){
for(int k=j;k<M;k+=j) DP[k]=min(DP[k],max(dp[j],fabs(a[i]-k)/a[i]));
}
dp=DP;
}
double res=inf;
for(int i=1;i<M;i++) res=min(res,dp[i]);
cout<<syosu(11)<<res<<endl;
} |
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[20], t; double dp[20][200000]; vector<int> s[200000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]), t = max(t, a[i]);
for (int i = 1; i < 2 * t; i++) {
for (int j = i; j < 2 * t; j += i) {
s[j].push_back(i);
}
}
for (int i = 1; i < 2 * t; i++) dp[0][i] = 1.0 * abs(a[0] - i) / a[0];
for (int i = 1; i < n; i++) {
for (int j = 1; j < 2 * t; j++) {
dp[i][j] = 1.0;
for (int k = 0; k < s[j].size(); k++) {
dp[i][j] = min(dp[i][j], max(dp[i - 1][s[j][k]], 1.0 * abs(a[i] - j) / a[i]));
}
}
}
double ret = 1.0;
for (int i = 1; i < 2 * t; i++) {
ret = min(ret, dp[n - 1][i]);
}
printf("%.9f\n", ret);
return 0;
} |
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
const int MAXK = 300010;
double dp[21][MAXK + 10];
int main() {
int N; cin >> N;
vector<int> A(N);
for(int i=0; i<N; i++) cin >> A[i];
fill(dp[0], dp[N+1], LONGINF);
for(int i=1; i<=MAXK; i++) {
dp[1][i] = 1.0 * abs(A[0] - i) / A[0];
}
for(int i=1; i<N; i++) {
for(int j=1; j<=MAXK; j++) {
for(int k=j; k<=MAXK; k+=j) {
chmin(dp[i+1][k], max(dp[i][j], 1.0 * abs(A[i] - k) / A[i]));
}
}
}
double ans = *min_element(dp[N], dp[N] + MAXK + 1);
printf("%.12f\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
#define N 30
using namespace std;
typedef long long ll;
int n,A[N];
unordered_map<ll,double> mem[N];
double calc(double a,double b){return abs(a-b)/a;}
double dfs(int idx,ll num){
if(idx==n) return 0;
if(mem[idx].count(num))return mem[idx][num];
double res=1LL<<55;
for(int i=idx;i<n;i++){
ll t =num * ((A[i]-1)/num+1);
res=min(res,max(calc(A[idx],t),dfs(idx+1,t)));
}
return mem[idx][num]=res;
}
double DP(){
unordered_map<ll,double> dp[2];
int f=0;
dp[0][1] = 0;
for(int i=0;i<n;i++,f=!f){
dp[!f].clear();
for(auto it = dp[f].begin();it!=dp[f].end();it++){
ll num = it->first;
double cost = it->second;
for(int j=num;;j+=num){
if(dp[!f].count(j))dp[!f][j] = min(dp[!f][j],max(calc(A[i],j),cost));
else dp[!f][j] = max(calc(A[i],j),cost);
if(j>A[n-1]) break;
}
}
}
double res=1LL<<55;
for(auto it = dp[f].begin();it!=dp[f].end();it++)res=min(res,it->second);
return res;
}
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>A[i];
printf("%.10f\n",DP());
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
const double INF = 1e9;
int N, a[20];
double dp[2][150001];
int main(){
fill_n( *dp, 2 * 150001, INF);
cin >> N;
for(int i = 0; i < N; ++i){
cin >> a[i];
}
for(int i = 1; i < 150001; ++i){
dp[0][i] = fabs(a[0] - i) / a[0];
}
for(int i = 0; i < N - 1; ++i){
for(int j = 1; j < 150001; ++j){
if(dp[i&1][j] != INF){
for(int k = j; k < 150001; k += j){
dp[(i + 1)&1][k] = min( dp[(i + 1)&1][k], max( dp[i&1][j], fabs( a[i + 1] - k) / a[i + 1]));
}
}
dp[i&1][j] = 1e9;
}
}
double ret = INF;
for(int i = 0; i < 150001; ++i) ret = min( ret, dp[(N - 1)&1][i]);
cout << fixed << setprecision(10) << ret << endl;
} |
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<queue>
#include<stack>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
typedef long long LL;
const int N = 200005;
const int M = 30;
const int inf = 1<<28;
const double eps = 1e-8;
using namespace std;
typedef pair<int,int> PII;
int n,a[N];
double dp[22][N];
void input(){
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
}
double DP(){
for(int i=1;i<=n;i++){
for(int j=1;j<=N-5;j++) dp[i][j]=-1.0;
}
for(int i=1;i<=N-5;i++){
dp[1][i]=1.0*abs(a[1]-i)/a[1];
}
for(int i=1;i<n;i++){
for(int j=1;j<=N-5;j++){
if(dp[i][j]<0) continue;
// if(i==n){
// printf("dp[%d][%d]=%.6f\n",i,j,dp[i][j]);
// continue;
// }
for(int k=j;k<=N-5;k+=j){
double tmp=max(1.0*abs(a[i+1]-k)/a[i+1],dp[i][j]);
// cout<<i+1<<" "<<k<<" "<<tmp<<endl;
if(dp[i+1][k]<0) dp[i+1][k]=tmp;
else dp[i+1][k]=min(dp[i+1][k],tmp);
}
}
}
double res=1e50;
for(int i=1;i<=N-5;i++){
if(dp[n][i]<0) continue;
res=min(res,dp[n][i]);
}
return res;
}
int main(){
//freopen("in","r",stdin);
while(scanf("%d",&n)>0){
input();
printf("%.10f\n",DP());
}
return 0;
} |
// OBツ嘉ッツ嘉債宿2011 Day3 F : Beautiful Currency
#include <iostream>
#include <cstdio>
#include <stdlib.h>
using namespace std;
int main(){
int N;
int a[20];
while(cin >> N){
for(int i=0;i<N;i++) cin >> a[i];
static double dp[2][200001];
for(int i=1;i<=200000;i++){
dp[0][i] = abs(a[0]-i)/(double)a[0];
}
int cur = 0, next = 1;
for(int i=1;i<N;i++){
for(int j=0;j<=200000;j++) dp[next][j] = 1e12;
for(int j=1;j<=200000;j++)
for(int k=j;k<=200000;k+=j)
dp[next][k] = min(dp[next][k], max(dp[cur][j], abs(a[i]-k)/(double)a[i]));
swap(cur, next);
}
double res = 1e12;
for(int i=1;i<=200000;i++) res = min(res, dp[cur][i]);
printf("%.10lf\n", res);
}
} |
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
using namespace std;
#define MAX_N 22
#define MAX_C 222222
#define INF 9999999999.99
vector<int>yakusuu[MAX_C];
double dp[MAX_N][MAX_C];
int n;
int x[MAX_N];
void yaku() {
for (int i = 1; i < MAX_C; i++) {
for (int j = i; j < MAX_C; j += i) {
yakusuu[j].push_back(i);
}
}
}
int main() {
yaku();
cin >> n;
x[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
dp[0][0] = INF;
for (int i = 1; i < MAX_C; i++) {
dp[1][i] = 1.0*abs(x[1] - i) / x[1];
}
for (int i = 2; i < MAX_N; i++) {
for (int j = 0; j < MAX_C; j++) {
dp[i][j] = INF;
}
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j < MAX_C; j++) {
for (int k = 0; k < yakusuu[j].size(); k++) {
double pos1 = dp[i - 1][yakusuu[j][k]];
double pos2 = 1.0*abs(x[i] - j) / x[i];
double pos3 = max(pos1, pos2);
dp[i][j] = min(dp[i][j], pos3);
}
}
}
double minx = INF;
for (int i = 0; i < MAX_C; i++) {
minx = min(minx, dp[n][i]);
}
cout << fixed << setprecision(15) << minx << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
//const int INF=1e9;
const double INF=1e100;
const int MOD=1e9+7;
const double EPS=1e-9;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
os<<'[';
rep(i,a.size()) os<<(i?" ":"")<<a[i];
return os<<']';
}
int main()
{
for(int n;cin>>n && n;){
vi a(n);
rep(i,n) cin>>a[i];
vvd dp(n+1,vd(200000,INF));
dp[0][1]=0;
rep(i,n) repi(j,1,dp[i].size())
for(int k=j;k<dp[i].size();k+=j)
dp[i+1][k]=min(dp[i+1][k],max(dp[i][j],1.*abs(k-a[i])/a[i]));
printf("%.12f\n",*min_element(all(dp[n])));
}
} |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
static const int M = 200000;
int main()
{
int N;
cin >> N;
int a[20];
for (int i = 0; i < N; i++) {
cin >> a[i];
}
static double dp[20][M];
for (int i = 0; i < N; i++) {
fill_n(dp[i], M, 1e10);
}
for (int i = 1; i < M; i++) {
dp[0][i] = fabs(a[0] - i)/double(a[0]);
}
for (int i = 0; i < N-1; i++) {
for (int j = 1; j < M; j++) {
for (int k = 1; k*j < M; k++) {
dp[i+1][k*j] = min(dp[i+1][k*j], max(dp[i][j], fabs(a[i+1] - k*j)/double(a[i+1])));
}
}
}
double ans = 1e10;
for (int i = 1; i < M; i++) {
ans = min(ans, dp[N-1][i]);
}
printf("%.9f\n", ans);
return 0;
} |
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define foreach(it,x) for(typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define sz(x) ((int)((x).size()))
#define fr(i,a,b) for(int i=(a); i<(b); ++i)
#define fo(i,t) fr(i,0,t)
#define fi(n) fo(i,n)
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> ii;
const int N = 2e5+5, M = 21;
bool ok[M][N];
inline int getint(){
int a;
scanf("%d", &a);
return a;
}
double EPS = 1e-9;
bool doit(int i, double delta, vi &a){
// base case
if(i==sz(a))
return true;
// general case
bool touched = false;
int bot = a[i]*(1-delta)-EPS+1;
int top = a[i]*(1+delta)+EPS;
fr(j,bot,top+1) // branch from every ok spot
if(ok[i][j])
for(int k=1; k*j<N; ++k){ // ok all its multiples
ok[i+1][k*j] = true;
touched = true;
}
// must complete from here
return touched ? doit(i+1, delta, a) : false;
}
int main() {
int n=getint();
vi a;
fi(n)
a.pb(getint());
double lo=0, hi=1;
fo(numtimes, 60){
memset(ok, false, sizeof(ok));
double mid = (lo+hi)/2;
int bot = a[0]*(1-mid)-EPS+1;
int top = a[0]*(1+mid)+EPS;
fr(i,bot,top+1)
ok[0][i] = true;
if(doit(0, mid, a))
hi = mid;
else
lo = mid;
}
printf("%.12lf\n", (lo+hi)/2);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef double ld;
const int maxA = 200000;
vector<int> a;
bool dp[20][maxA+1]; // dp[i][j]: j???i???????????§?????????
bool check(ld th, int b, int n) {
return abs(a[n]-b) <= a[n]*th;
}
bool check(ld th) {
int N = a.size();
fill(dp[0], dp[20], false);
for (int b0 = 1; b0 <= maxA; ++b0) {
dp[0][b0] = check(th, b0, 0);
}
for (int i = 1; i < a.size(); ++i) {
for (int j = 1; j <= maxA; ++j) {
if (dp[i-1][j]) {
for (int k = j; k <= maxA; k += j) {
if (check(th, k, i)) {
dp[i][k] = true;
}
}
}
}
}
for (int j = 1; j <= maxA; ++j) {
if (dp[N-1][j]) return true;
}
return false;
}
int main() {
int N; cin >> N; a.resize(N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
ld l = 0, r = 1e10;
for (int t = 0; t < 100; ++t) {
ld m = (l + r) / 2;
if ( check(m) ) {
r = m;
}
else {
l = m;
}
}
assert(check(r));
cout << fixed << setprecision(10) << r << endl;
} |
#include <stdio.h>
#include <cmath>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int a[20];
int n;
bool DFS(int k, int m, double r){
int s=ceil(a[k]-a[k]*r);
if(s==0)s=1;
int e=ceil(a[k]+a[k]*r);
for(int p=((s-1)/m+1)*m;p<e;p+=m)
if(k==n-1)return true;
else if(DFS(k+1,p,r))return true;
return false;
}
bool C(double r){
return DFS(0,1,r);
}
int main(){
scanf("%d",&n);
REP(i,n)scanf("%d",&a[i]);
double u=1.0, l=0.0;
while(u-l>1e-9){
double mid=(u+l)*0.5;
if(C(mid))u=mid;
else l=mid;
}
printf("%.10f\n",u);
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.