Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #pragma GCC optimize("Ofast,fast-math,unroll-loops")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,tune=native")
  5.  
  6. #define all(x) x.begin(),x.end()
  7. #define rall(x) x.rbegin(),x.rend()
  8. #define size(x) (int)x.size()
  9. #define f first
  10. #define s second
  11.  
  12. using namespace std;
  13.  
  14. typedef long long ll;
  15. typedef long double ld;
  16.  
  17. void solve() {
  18.     vector<vector<int>> a(4, vector<int>(7));
  19.     int n = 28;
  20.     vector<int> count(29, 0), bad(29, 0), sum(29, 0);
  21.     int i, j;
  22.     bool ch;
  23.     int cnt;
  24.     int ccnt;
  25.     int t = 0;
  26.     for(int mask = 0; mask < (1 << n); mask++) {
  27.         ccnt = 0;
  28.         for(i = 0; i < n; i++) {
  29.             if(mask & (1 << i)) {
  30.                 a[i / 7][i % 7] = 1;
  31.                 ccnt++;
  32.             }else {
  33.                 a[i / 7][i % 7] = 0;
  34.             }
  35.         }
  36.         do {
  37.             ch = false;
  38.             for(i = 0; i < 4; i++) {
  39.                 cnt = 0;
  40.                 for(j = 0; j < 7; j++) {
  41.                     cnt += a[i][j];
  42.                 }
  43.                 if(cnt <= 2 && cnt > 0) {
  44.                     for(j = 0; j < 7; j++) {
  45.                         a[i][j] = 0;
  46.                     }
  47.                     ch = true;
  48.                 }
  49.             }
  50.             for(i = 0; i < 7; i++) {
  51.                 cnt = 0;
  52.                 for(j = 0; j < 4; j++) {
  53.                     cnt += a[j][i];
  54.                 }
  55.                 if(cnt == 1) {
  56.                     for(j = 0; j < 4; j++) {
  57.                         a[j][i] = 0;
  58.                     }
  59.                     ch = true;
  60.                 }
  61.             }
  62.         }while(ch);
  63.         cnt = 0;
  64.         for(i = 0; i < 4; i++) {
  65.             for(j = 0; j < 7; j++) {
  66.                 if(a[i][j] == 1) {
  67.                     cnt++;
  68.                 }
  69.             }
  70.         }
  71.         count[ccnt]++;
  72.         sum[ccnt] += cnt;
  73.         if(cnt > 0) {
  74.             bad[ccnt]++;
  75.         }
  76.         if(t == 0) {
  77.             cout << mask << "\n";
  78.         }
  79.         t++;
  80.         if(t == 1000000) {
  81.             t = 0;
  82.         }
  83.     }
  84.     for(int i = 0; i <= 28; i++) {
  85.         cout << "p[" << i << "] = " << ((double)bad[i]) / count[i] << ";\n";
  86.         cout << "m[" << i << "] = " << ((double)sum[i]) / count[i] << ";\n";
  87.     }
  88. }
  89.  
  90. int main() {
  91. #ifndef HOME
  92.     freopen("input.txt", "r", stdin);
  93.     freopen("output.txt", "w", stdout);
  94. #endif
  95. //    ios_base::sync_with_stdio(false);
  96. //    cin.tie(nullptr);
  97. //    cout.tie(nullptr);
  98.     solve();
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement