Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <fstream>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <queue>
  9. #include <stack>
  10. #include <algorithm>
  11. #include <cmath>
  12. #include <cstdio>
  13. #include <cstring>
  14. #include <ctime>
  15. #include <cstdlib>
  16. #include <cctype>
  17. #include <utility>
  18. #include <complex>
  19. #include <deque>
  20. #include <functional>
  21.  
  22. int dummy_func() {return 0;}
  23.  
  24. using namespace std;
  25.  
  26. typedef long long LL;
  27. typedef long double LD;
  28.  
  29. const int N_MAX = 11;
  30.  
  31. int n, q, L0;
  32. int leng [N_MAX];
  33.  
  34. LD dist(LD F1, LD F2)
  35. {
  36.     return max(F1 / F2, F2 / F1);
  37. }
  38.  
  39. int main()
  40. {
  41.     freopen("input.txt", "r", stdin);
  42.     freopen("output.txt", "w", stdout);
  43.  
  44.     cin >> n >> L0;
  45.     for (int i = 0; i < n; i++) cin >> leng[i];
  46.  
  47.     cin >> q;
  48.     for (int i = 0; i < q; i++)
  49.     {
  50.         string s;
  51.         cin >> s;
  52.  
  53.         int a, b;
  54.         if (s.size() == 2)
  55.         {
  56.             if (s[0] == 'A') a = 0;
  57.             if (s[0] == 'B') a = 2;
  58.             if (s[0] == 'C') a = -9;
  59.             if (s[0] == 'D') a = -7;
  60.             if (s[0] == 'E') a = -5;
  61.             if (s[0] == 'F') a = -4;
  62.             if (s[0] == 'G') a = -2;
  63.             b = s[1] - '1';
  64.         }
  65.         else
  66.         {
  67.             if (s.substr(0, 2) == "C#") a = -8;
  68.             if (s.substr(0, 2) == "Db") a = -8;
  69.             if (s.substr(0, 2) == "D#") a = -6;
  70.             if (s.substr(0, 2) == "Eb") a = -6;
  71.             if (s.substr(0, 2) == "F#") a = -3;
  72.             if (s.substr(0, 2) == "Gb") a = -3;
  73.             if (s.substr(0, 2) == "G#") a = -1;
  74.             if (s.substr(0, 2) == "Ab") a = -1;
  75.             if (s.substr(0, 2) == "A#") a = 1;
  76.             if (s.substr(0, 2) == "Bb") a = 1;
  77.             b = s[2] - '1';
  78.         }
  79.  
  80.         LD F0 = pow(2, a / 12.0 + b) * 440;
  81.  
  82.         LD bestC = 1e18;
  83.         int bestMask, bestK;
  84.         for (int mask = 0; mask < (1 << n); mask++)
  85.         {
  86.             LL L = L0;
  87.             for (int i = 0; i < n; i++)
  88.                 if (mask & (1 << i)) L += leng[i];
  89.  
  90.             LL k1 = (LL)(2 * L * F0) / 340000.0;
  91.             LL k2 = k1 + 1;
  92.             LL k3 = k1 - 1;
  93.  
  94.             LD F1 = (340000.0 * k1 / 2.0) / L;
  95.             LD C1 = dist(F0, F1);
  96.             if (C1 < bestC && k1 > 1)
  97.             {
  98.                 bestC = C1;
  99.                 bestMask = mask;
  100.                 bestK = k1;
  101.             }
  102.  
  103.             LD F2 = (340000.0 * k2 / 2.0) / L;
  104.             LD C2 = dist(F0, F2);
  105.             if (C2 < bestC && k2 > 1)
  106.             {
  107.                 bestC = C2;
  108.                 bestMask = mask;
  109.                 bestK = k2;
  110.             }
  111.  
  112.             LD F3 = (340000.0 * k3 / 2.0) / L;
  113.             LD C3 = dist(F0, F3);
  114.             if (C3 < bestC && k3 > 1)
  115.             {
  116.                 bestC = C3;
  117.                 bestMask = mask;
  118.                 bestK = k3;
  119.             }
  120.         }
  121.  
  122.         for (int i = 0; i < n; i++)
  123.             if (bestMask & (1 << i))
  124.                 cout << 'o';
  125.             else
  126.                 cout << '.';
  127.  
  128.         cout << ' ' << bestK << ' ' << fixed << setprecision(8) << 12 * (log(bestC) / log(2.0)) << '\n';
  129.     }
  130.  
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement