#include<bits/stdc++.h> #define db double using namespace std; const int N = 25003; db T[2][N], V[N]; inline db mx ( db d1, db d2) { if (d1 < d2) return d2; return d1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n , t; cin>>n>>t; string s; for (int i = 0; i < n; ++i) { cin>>s; db a = 0, d = 0.1; a += (db) (s[0] - '0'); for (int j = 2; j < s.length(); ++j) { a += (db) (s[j] - '0') * d; d *= 0.1; } V[i] = a; } sort(V, V + n, greater<db>()); int m = 1, k = 1, l, il = 0, ir = 0; int borderLeft = (n-t) / 2, borderRight = t + ((n-t+1) / 2); T[k][0] = 1.; db pmax = 0., pRight = 0.; for (int i = 1; i <= n; ++i) { l = k ^ 1; db p = 0.; T[l][il] = 0.; // cout<<"##### "<<i<<' '<<V[i-1]<<'\n'; for (int j = il; j <= ir; ++j) { T[l][j] += (1. - V[i-1]) * T[k][j]; T[l][j+1] = V[i-1] * T[k][j]; // cout<<j<<' '<<T[l][j]<<'\n'; if (2 * j >= t + i) { p += T[l][j]; } } // cout<<ir+1<<' '<<T[l][ir+1]<<'\n'; if (n - 2 * i < t) { ++il; } if (2 * i - n < t) { ++ir; if (2 * ir >= t + i) p += T[l][ir]; } else { pRight += T[l][ir+1]; } // cout<<"p: "<< p << " pright: "<<pRight<<'\n'; pmax = mx(pmax, p + pRight); k ^= 1; } cout << fixed << setprecision(9) << pmax << '\n'; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include<bits/stdc++.h> #define db double using namespace std; const int N = 25003; db T[2][N], V[N]; inline db mx ( db d1, db d2) { if (d1 < d2) return d2; return d1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n , t; cin>>n>>t; string s; for (int i = 0; i < n; ++i) { cin>>s; db a = 0, d = 0.1; a += (db) (s[0] - '0'); for (int j = 2; j < s.length(); ++j) { a += (db) (s[j] - '0') * d; d *= 0.1; } V[i] = a; } sort(V, V + n, greater<db>()); int m = 1, k = 1, l, il = 0, ir = 0; int borderLeft = (n-t) / 2, borderRight = t + ((n-t+1) / 2); T[k][0] = 1.; db pmax = 0., pRight = 0.; for (int i = 1; i <= n; ++i) { l = k ^ 1; db p = 0.; T[l][il] = 0.; // cout<<"##### "<<i<<' '<<V[i-1]<<'\n'; for (int j = il; j <= ir; ++j) { T[l][j] += (1. - V[i-1]) * T[k][j]; T[l][j+1] = V[i-1] * T[k][j]; // cout<<j<<' '<<T[l][j]<<'\n'; if (2 * j >= t + i) { p += T[l][j]; } } // cout<<ir+1<<' '<<T[l][ir+1]<<'\n'; if (n - 2 * i < t) { ++il; } if (2 * i - n < t) { ++ir; if (2 * ir >= t + i) p += T[l][ir]; } else { pRight += T[l][ir+1]; } // cout<<"p: "<< p << " pright: "<<pRight<<'\n'; pmax = mx(pmax, p + pRight); k ^= 1; } cout << fixed << setprecision(9) << pmax << '\n'; } |