fork download
  1. #include <set>
  2. #include <map>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <string>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <sstream>
  13. #include <iomanip>
  14. #include <complex>
  15. #include <iostream>
  16. #include <algorithm>
  17.  
  18. #include <ctime>
  19. #include <deque>
  20. #include <bitset>
  21. #include <cctype>
  22. #include <utility>
  23. #include <cassert>
  24. using namespace std;
  25.  
  26. #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
  27. #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
  28. #define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
  29. #define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
  30.  
  31. #define DEBUG(x) { cout << #x << " = " << x << endl; }
  32. #define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
  33. #define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
  34.  
  35. const int MN = 55;
  36.  
  37. double f[MN][MN], w, p, a[MN];
  38. int n;
  39.  
  40. bool check() {
  41. multiset<double> pieces;
  42. FOR(i,1,n) pieces.insert(a[i]);
  43. while (pieces.size() > 1) {
  44. double a = *pieces.begin(); pieces.erase(pieces.begin());
  45. double b = *pieces.begin(); pieces.erase(pieces.begin());
  46.  
  47. double x = (a + b) / (1 - p);
  48. pieces.insert(x);
  49. }
  50. return *pieces.begin() < w + 1e-9;
  51. }
  52.  
  53. int main() {
  54. ios :: sync_with_stdio(false); cin.tie(NULL);
  55. cout << (fixed) << setprecision(9);
  56. int test; cin >> test;
  57. while (test--) {
  58. cin >> w >> p >> n;
  59. p /= 100.0;
  60. FOR(i,1,n) cin >> a[i];
  61.  
  62. if (!check()) {
  63. cout << -1 << endl;
  64. continue;
  65. }
  66.  
  67. double l = 0.0, r = w, res = 0.0;
  68. ++n;
  69. REP(turn,50) {
  70. double mid = (l + r) / 2.0;
  71. a[n] = mid;
  72. if (check()) {
  73. res = mid;
  74. l = mid;
  75. } else r = mid;
  76. }
  77. cout << res << endl;
  78. }
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0s 3504KB
stdin
3
100 10 2
15
21
45 15 3
11
11
11
50 0 3
10
20
25
stdout
50.000000001
0.000000000
-1