joylintp

Untitled

May 23rd, 2021
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.86 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //#pragma gcc optimize("Ofast,unroll-loops")
  5. //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
  6. //#define int long long
  7. //#define double long double
  8. #define MP make_pair
  9. #define F first
  10. #define S second
  11. #define MOD 43200000000000
  12.  
  13. random_device rd;
  14. default_random_engine gen = default_random_engine(rd());
  15. uniform_int_distribution<int> r3(0, 2), r5050(0, 5049), r60(0, 59);
  16.  
  17. long double gmx = 0;
  18. string gbst;
  19.  
  20. long double score(string s, int E)
  21. {
  22.     int W = 10, R = 0, P = 0, S = 0;
  23.     long double ret = (long double)W / 3 + (long double)E / 3;
  24.     for (int i = 1; i < 60; i++)
  25.     {
  26.         if (s[i - 1] == 'R')
  27.             R++;
  28.         else if (s[i - 1] == 'P')
  29.             P++;
  30.         else
  31.             S++;
  32.  
  33.         long double pR = (long double)S / i, pP = (long double)R / i, pS = (long double)P / i;
  34.         if (s[i] == 'R')
  35.             ret += pR * E + pS * W;
  36.         else if (s[i] == 'P')
  37.             ret += pP * E + pR * W;
  38.         else
  39.             ret += pS * E + pP * W;
  40.     }
  41.     return ret;
  42. }
  43.  
  44. void gen1st(int Ev)
  45. {
  46.     long double sum = 0, mx = 0;
  47.     string bst;
  48.  
  49.     freopen("tmp.txt", "w", stdout);
  50.     for (int i = 0; i < 100; i++)
  51.     {
  52.         string s;
  53.         for (int j = 0; j < 60; j++)
  54.             s += "RPS"[r3(gen)];
  55.         cout << s << ' ' << fixed << setprecision(20) << score(s, Ev) << '\n', sum += score(s, Ev);
  56.  
  57.         if (score(s, Ev) > mx)
  58.             mx = score(s, Ev), bst = s;
  59.     }
  60.     cerr << "1st AVG: " << fixed << setprecision(20) << sum << '\n';
  61.     cerr << "BEST: " << bst << ' ' << fixed << setprecision(20) << score(bst, Ev) << '\n';
  62.     if (score(bst, Ev) > gmx)
  63.         gmx = score(bst, Ev), gbst = bst;
  64. }
  65.  
  66. bool cmp(pair<string, long double> a, pair<string, long double> b)
  67. {
  68.     return a.S > b.S;
  69. }
  70.  
  71. void gennext(int Ev, bool prt)
  72. {
  73.     freopen("tmp.txt", "r", stdin);
  74.     vector<pair<string, long double>> v(100);
  75.     for (auto &p : v)
  76.         cin >> p.F >> p.S;
  77.     sort(v.begin(), v.end(), cmp);
  78.  
  79.     vector<int> ns;
  80.     for (int i = 0; i < 100; i++)
  81.         for (int j = 0; j < 100 - i; j++)
  82.             ns.push_back(i);
  83.  
  84.     long long sum = 0, mx = 0;
  85.     string bst;
  86.     freopen("tmp.txt", "w", stdout);
  87.     for (int i = 0; i < 100; i++)
  88.     {
  89.         int id = ns[r5050(gen)], pos = r60(gen);
  90.         string ts = v[id].F;
  91.         ts[pos] = "RPS"[r3(gen)];
  92.  
  93.         long double ns = score(ts, Ev);
  94.         cout << ts << ' ' << ns << '\n', sum += ns;
  95.         if (ns > mx)
  96.             mx = ns, bst = ts;
  97.     }
  98.     if (prt)
  99.     {
  100.         cerr << "next AVG: " << fixed << setprecision(20) << sum << '\n';
  101.         cerr << "BEST: " << bst << ' ' << fixed << setprecision(20) << score(bst, Ev) << '\n';
  102.     }
  103.     if (score(bst, Ev) > gmx)
  104.     {
  105.         gmx = score(bst, Ev), gbst = bst;
  106.         cerr << "GLOBAL BEST: " << gbst << ' ' << fixed << setprecision(20) << gmx << '\n';
  107.     }
  108. }
  109.  
  110. signed main()
  111. {
  112.     int E = 10;
  113.  
  114.     gen1st(E);
  115.     for (int i = 0; i <= 100000; i++)
  116.         gennext(E, false);
  117.     //gennext(E, true);
  118.  
  119.     //cerr << "GLOBAL BEST: " << gbst << ' ' << fixed << setprecision(20) << score(gbst, E) << '\n';
  120.  
  121.     return 0;
  122. }
  123.  
  124. //      *   *  *****  *   *  *   *   ****  ****    ****     **    **
  125. //     *   *  *      **  *  *   *  *      *   *  *        * *   * *
  126. //    *****  *****  * * *  *   *  *      ****   *       *  *     *
  127. //   *   *      *  *  **  *   *  *      *  *   *       *****    *
  128. //  *   *  *****  *   *   ***    ****  *   *    ****     *   *****
  129.  
  130. //      *****  *****  *   *  *      *****  *   *  *****  *****
  131. //        *   *   *  *   *  *        *    **  *    *    *   *
  132. //       *   *   *  *****  *        *    * * *    *    *****
  133. //   *  *   *   *    *    *        *    *  **    *    *
  134. //  ****   *****    *    *****  *****  *   *    *    *
  135.  
Advertisement
Add Comment
Please, Sign In to add comment