forked from arshdeep/topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortEstimate.cpp
More file actions
36 lines (31 loc) · 724 Bytes
/
SortEstimate.cpp
File metadata and controls
36 lines (31 loc) · 724 Bytes
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
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <queue>
#include <iterator>
#include <sstream>
#include <cassert>
#include <stack>
using namespace std;
/* sortEstimate http://community.topcoder.com/stat?c=problem_statement&pm=3561&rd=6519 */
double howMany(int c, int time)
{
double a = double(time) / c;
double Min = 1e-10, Max = time + 1;
while (Max-Min > (1+1e-10)) {
double Mid = (Min + Max) / 2, v=Mid * log(Mid) / log(2.0);
if(v>a)Max=Mid; else Min=Mid;
}
return (Min+Max)/2;
}
int main(int argc, char *argv[])
{
cout<<howMany(1, 2000000000)<<endl;
cout<<howMany(37, 12392342)<<endl;
getchar();
return 0;
}