Advertisement
Guest User

Untitled

a guest
Dec 8th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #include <cstring>
  11. #include <cstdlib>
  12. #include <cmath>
  13. #include <string>
  14. #include <memory.h>
  15. #include <sstream>
  16. #include <ctime>
  17. #include <bitset>
  18. using namespace std;
  19.  
  20. #pragma comment(linker, "/stack:64000000")
  21.  
  22. static const int N = 1000;
  23. static const int M = 500;
  24.  
  25. bitset<N> nextRandString()
  26. {
  27. bitset<N> result;
  28. for(int i = 0; i < N; i++)
  29. result[i] = (rand() % 2);
  30. return result;
  31. }
  32.  
  33. bitset<N> nextRandSample()
  34. {
  35. bitset<N> result;
  36. for(int i = 0; i < N; i++)
  37. result[i] = (rand() % 4 ? 0 : 1);
  38. return result;
  39. }
  40.  
  41. bool match(const bitset<N> &b1, const bitset<N> &b2)
  42. {
  43. bitset<N> b3 = b1 ^ b2;
  44. int k = b3.count();
  45. return (k == N / 2) || (k == N);
  46. }
  47.  
  48. int main()
  49. {
  50. srand(42);
  51. bitset<N> known;
  52. vector<bitset<N>> samples;
  53. vector<int> bcnt(N, 0);
  54.  
  55. int dbg_known_checks = 0;
  56.  
  57. for (int i = 0; i < M; i++)
  58. {
  59. bitset<N> current = nextRandString();
  60. samples.push_back(current);
  61. for (int j = 0; j < N; j++)
  62. bcnt[j] += current[j];
  63. if (!(match(current, known)))
  64. continue;
  65.  
  66. bitset<N> modificator;
  67. for (int j = 0; j < N; j++)
  68. modificator[j] = ((bcnt[j] < i / 2) ? 0 : 1);
  69.  
  70. while (1)
  71. {
  72. known = nextRandSample() ^ modificator;
  73. ++dbg_known_checks;
  74. bool ok = true;
  75. for (int j = 0; j <= i; j++)
  76. if (match(known, samples[j]))
  77. {
  78. ok = false;
  79. break;
  80. }
  81. if (ok)
  82. break;
  83. }
  84. }
  85. cout << dbg_known_checks;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement