Advertisement
Guest User

2022 sc2 katowice groups

a guest
Jan 31st, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <algorithm>
  5. typedef unsigned int uint;
  6.  
  7. uint const G=4;
  8. uint const L=5;
  9. uint const N=G*L;
  10. struct player
  11. {
  12.     char const *name=0;
  13.     char race=0;
  14.     uint points=0;
  15. };
  16. player const P[L][G]=
  17. {
  18.     {
  19.         {"Maru",'T',3185},
  20.         {"Rogue",'Z',2937},
  21.         {"Trap",'P',2897},
  22.         {"Serral",'Z',2670}
  23.     },
  24.     {
  25.         {"Clem",'T',2536},
  26.         {"Dark",'Z',2397},
  27.         {"Cure",'T',2153},
  28.         {"Zest",'P',1976}
  29.     },
  30.     {
  31.         {"Reynor",'Z',1914},
  32.         {"Heromarine",'T',1573},
  33.         {"Solar",'Z',1369},
  34.         {"Time",'T',1333}
  35.     },
  36.     {
  37.         {"Scarlett",'Z',1315},
  38.         {"Neeb",'P',1265},
  39.         {"Bunny",'T',1240},
  40.         {"Special",'T',1237}
  41.     },
  42.     {
  43.         {"Dream",'T',1172},
  44.         {"Zoun",'P',1106},
  45.         {"Showtime",'P',752},
  46.         {"Lambo",'Z',740}
  47.     }
  48. };
  49. uint sum_P=0;
  50.  
  51. uint perm[L][G]=
  52. {
  53.     {0,1,2,3},
  54.     {0,1,2,3},
  55.     {0,1,2,3},
  56.     {0,1,2,3},
  57.     {0,1,2,3}
  58. };
  59.  
  60. uint sgp[L][G]={};
  61. uint n=0,nl=0;
  62. uint const M=11000;
  63. uint nmp[M]={};
  64. uint nmg[G]={};
  65. uint nmgt=0;
  66. double const D=297.0;
  67. double limit_D=0.0;
  68. uint const limit=10056; // d~297.1
  69.  
  70. int min_sd2=0;
  71.  
  72. void rec(uint l)
  73. {
  74.     if(l<L)
  75.     {
  76.         do
  77.         {
  78.             for(uint i=0; i<G; ++i)
  79.                 sgp[l][i]=sgp[l-1][i]+P[l][perm[l][i]].points;
  80.             rec(l+1);
  81.         }
  82.         while(std::next_permutation(perm[l],perm[l]+G));
  83.     }
  84.     else
  85.     {
  86.         uint mp=sgp[L-1][0];
  87.         uint mg=0;
  88.         bool mgt=0;
  89.         for(uint i=1; i<G; ++i)
  90.         {
  91.             if(mp<sgp[L-1][i])
  92.             {
  93.                 mp=sgp[L-1][i];
  94.                 mg=i;
  95.                 mgt=0;
  96.             }
  97.             else if(mp==sgp[L-1][i])
  98.             {
  99.                 mgt=1;
  100.             }
  101.         }
  102.         ++nmp[mp];
  103.         if(limit<=mp)
  104.         {
  105.             ++nmg[mg];
  106.             nmgt+=mgt;
  107.             ++nl;
  108.         }
  109.         bool has_min_sd2=0;
  110.         {
  111.             int sd2=0;
  112.             for(uint i=0; i<G; ++i)
  113.             {
  114.                 int d=int(sum_P)-int(G*sgp[L-1][i]);
  115.                 int d2=d*d;
  116.                 sd2+=d2;
  117.             }
  118.             if(sd2==min_sd2)
  119.                 std::cout << "dup" << std::endl;
  120.             if(n==0 || sd2<min_sd2)
  121.             {
  122.                 min_sd2=sd2;
  123.                 has_min_sd2=1;
  124.             }
  125.         }
  126.         if(has_min_sd2)
  127.         {
  128.             std::cout << double(min_sd2)/G/G << std::endl;
  129.             for(uint j=0; j<G; ++j)
  130.             {
  131.                 std::cout
  132.                     //<< "ABCDEF"[j] << " "
  133.                     << sgp[L-1][j] << " ";
  134.                 for(uint i=0; i<L; ++i)
  135.                 {
  136.                     uint k=perm[i][j];
  137.                     std::cout
  138.                         << P[i][k].name << ","
  139.                         << P[i][k].race << ","
  140.                         << P[i][k].points
  141.                         << " ";
  142.                 }
  143.                 std::cout << std::endl;
  144.             }
  145.         }
  146.         ++n;
  147.     }
  148. }
  149.  
  150. int main()
  151. {
  152.     for(uint l=0; l<L; ++l)
  153.         for(uint i=0; i<G; ++i)
  154.             sum_P+=P[l][i].points;
  155.     limit_D=double(D*L*(G-1)+sum_P)/G;
  156.     for(uint i=0; i<G; ++i)
  157.         sgp[0][i]=P[0][i].points;
  158.     rec(1);
  159.     std::cout << "n=" << n << " sum_P=" << sum_P << " limit_D=" << limit_D << std::endl;
  160.  
  161.     std::cout << "nmg=(";
  162.     for(uint i=0; i<G; ++i)
  163.         std::cout << (i?",":"") << nmg[i];
  164.     std::cout << "), nmgt=" << nmgt << " nl=" << nl << std::endl;
  165.     for(uint m=0,sn=0; m<M; ++m)
  166.         if(nmp[m])
  167.         {
  168.             double avg_mg=double(m)/L;
  169.             double avg_og=double(sum_P-m)/((G-1)*L);
  170.             double d=avg_mg-avg_og;
  171.             if(limit-100<m)
  172.             {
  173.                 std::cout << m << " " << nmp[m] << " " << sn
  174.                     << std::fixed << std::setprecision(2)
  175.                     << " " << avg_og << " " << avg_mg << " d=" << d
  176.                     << std::fixed << std::setprecision(6)
  177.                     << " " << double(n-sn)/n
  178.                     << std::endl;
  179.             }
  180.             sn+=nmp[m];
  181.             //std::cout << m << "," << nmp[m] << std::endl;
  182.             //std::cout << m << "," << sn << std::endl;
  183.         }
  184.  
  185.    
  186.     return 0;
  187. }
  188.  
  189. /*
  190.  
  191. min variation of sum group points
  192.  
  193. 8951 Maru,T,3185 Zest,P,1976 Solar,Z,1369 Scarlett,Z,1315 Zoun,P,1106
  194. 8924 Rogue,Z,2937 Dark,Z,2397 Heromarine,T,1573 Neeb,P,1265 Showtime,P,752
  195. 8944 Trap,P,2897 Cure,T,2153 Reynor,Z,1914 Bunny,T,1240 Lambo,Z,740
  196. 8948 Serral,Z,2670 Clem,T,2536 Time,T,1333 Special,T,1237 Dream,T,1172
  197.  
  198. */
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement