fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define N 100
  4. void display(bool a[]) {
  5. int i=0;
  6. while(i<31) printf("%2d ",a[i++]);
  7. }
  8. void assign(bool a[],int zeros) {
  9. for(int i=0;i<31;i++)
  10. (i<zeros)?a[i] = 0:a[i] = 1;
  11. }
  12. int main() {
  13. srand(time(NULL));
  14. bool a[31];
  15. // header
  16. for(int i=0;i<31;i++) printf("%2d ",i);
  17. printf("\n\n");
  18. int max_probes = 0;
  19. for(int iteration = 1;iteration <= N;iteration++) {
  20. int zeros = rand()%32;
  21. assign(a,zeros);
  22. sort(a,a+31);
  23. int low,high,mid,ans;
  24. std::vector<int> seq;
  25.  
  26. low = 0;
  27. high = 31;
  28. while(low < high) {
  29. mid = low + floor((high - low) / 2);
  30. seq.push_back(mid);
  31. if(a[mid] == 0) {
  32. low = mid + 1;
  33. ans = low;
  34. if(a[mid + 1] == 1) break;
  35. } else {
  36. high = mid;
  37. ans = high;
  38. if(mid > 0)
  39. if(a[mid - 1] == 0) break;
  40.  
  41. }
  42. }
  43.  
  44. display(a);
  45. printf(" | probes=%d ",seq.size());
  46. for(auto e:seq) printf("%d ",e);
  47. printf(" | at = %dth\n",ans);
  48. //if(ans == 15) printf("\nHHH=-------------\n");
  49. max_probes = max(max_probes,(int)(seq.size()));
  50. seq.clear();
  51. }
  52. printf("%d\n",max_probes);
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:25: fatal error: bits/stdc++.h: No such file or directory
 #include <bits/stdc++.h>
                         ^
compilation terminated.
stdout
Standard output is empty