Advertisement
_rashed

UVA 542

Jun 28th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. map<pair<int,int>,set<int>> opp;
  9. double p[16][16];
  10. string names[16];
  11. double mem[16][4];
  12.  
  13. double solve(int idx, int rd) {
  14.     if(mem[idx][rd] != -1) {
  15.         return mem[idx][rd];
  16.     }
  17.     if(rd == 0) {
  18.         return p[idx][*(opp[{idx,0}].begin())];
  19.     }
  20.     double &ret = mem[idx][rd];
  21.     ret = 0;
  22.     for(int e : opp[{idx,rd}]) {
  23.         ret += p[idx][e] * solve(e,rd-1);
  24.     }
  25.     ret *= solve(idx,rd-1);
  26.     return ret;
  27. }
  28.  
  29. int rd_idx(int x) {
  30.     int ret = 0;
  31.     while(x > 2) {
  32.         x /= 2;
  33.         ret++;
  34.     }
  35.     return ret;
  36. }
  37.  
  38. int main()
  39. {
  40.     ios_base::sync_with_stdio(false);
  41.     cin.tie(NULL);
  42.     cout.tie(NULL);
  43.     cout.precision(2);
  44.     cout << fixed;
  45.     for(int i = 0; i < 16; i++) {
  46.         for(int j = 0; j < 4; j++) {
  47.             mem[i][j] = -1;
  48.         }
  49.     }
  50.     for(int i = 0; i < 16; i++) {
  51.         cin >> names[i];
  52.     }
  53.     for(int i = 0; i < 16; i++) {
  54.         for(int j = 0; j < 16; j++) {
  55.             cin >> p[i][j];
  56.  
  57.             p[i][j] /= 100.0;
  58.         }
  59.     }
  60.     for(int i = 0; i < 16; i++) {
  61.         for(int j = 2; j <= 16; j *= 2) {
  62.             int l = i/j;
  63.             for(int k = l*j; k < (l+1)*j; k++) {
  64.                 bool flag = (k != i);
  65.                 for(int o = j/2; o > 1; o /= 2) {
  66.                     int rd = rd_idx(o);
  67.                     if(opp[{i,rd}].find(k) != opp[{i,rd}].end()) {
  68.                         flag = false;
  69.                         break;
  70.                     }
  71.                 }
  72.                 if(flag) {
  73.  
  74.                     opp[{i,rd_idx(j)}].insert(k);
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     for(int i = 0; i < 16; i++) {
  80.         cout << names[i] << string(10-names[i].length(),' ') << " p=" << solve(i,3)*100.0 << "%\n";
  81.     }
  82.  
  83.     return 0;
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement