Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <iomanip>
- #include <vector>
- #include <set>
- #include <map>
- #include <queue>
- #include <stack>
- #include <algorithm>
- #include <cmath>
- #include <cstdio>
- #include <cstring>
- #include <ctime>
- #include <cstdlib>
- #include <cctype>
- #include <utility>
- #include <complex>
- #include <deque>
- #include <functional>
- int dummy_func() {return 0;}
- using namespace std;
- typedef long long LL;
- typedef long double LD;
- const int N_MAX = 11;
- int n, q, L0;
- int leng [N_MAX];
- LD dist(LD F1, LD F2)
- {
- return max(F1 / F2, F2 / F1);
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- cin >> n >> L0;
- for (int i = 0; i < n; i++) cin >> leng[i];
- cin >> q;
- for (int i = 0; i < q; i++)
- {
- string s;
- cin >> s;
- int a, b;
- if (s.size() == 2)
- {
- if (s[0] == 'A') a = 0;
- if (s[0] == 'B') a = 2;
- if (s[0] == 'C') a = -9;
- if (s[0] == 'D') a = -7;
- if (s[0] == 'E') a = -5;
- if (s[0] == 'F') a = -4;
- if (s[0] == 'G') a = -2;
- b = s[1] - '1';
- }
- else
- {
- if (s.substr(0, 2) == "C#") a = -8;
- if (s.substr(0, 2) == "Db") a = -8;
- if (s.substr(0, 2) == "D#") a = -6;
- if (s.substr(0, 2) == "Eb") a = -6;
- if (s.substr(0, 2) == "F#") a = -3;
- if (s.substr(0, 2) == "Gb") a = -3;
- if (s.substr(0, 2) == "G#") a = -1;
- if (s.substr(0, 2) == "Ab") a = -1;
- if (s.substr(0, 2) == "A#") a = 1;
- if (s.substr(0, 2) == "Bb") a = 1;
- b = s[2] - '1';
- }
- LD F0 = pow(2, a / 12.0 + b) * 440;
- LD bestC = 1e18;
- int bestMask, bestK;
- for (int mask = 0; mask < (1 << n); mask++)
- {
- LL L = L0;
- for (int i = 0; i < n; i++)
- if (mask & (1 << i)) L += leng[i];
- LL k1 = (LL)(2 * L * F0) / 340000.0;
- LL k2 = k1 + 1;
- LL k3 = k1 - 1;
- LD F1 = (340000.0 * k1 / 2.0) / L;
- LD C1 = dist(F0, F1);
- if (C1 < bestC && k1 > 1)
- {
- bestC = C1;
- bestMask = mask;
- bestK = k1;
- }
- LD F2 = (340000.0 * k2 / 2.0) / L;
- LD C2 = dist(F0, F2);
- if (C2 < bestC && k2 > 1)
- {
- bestC = C2;
- bestMask = mask;
- bestK = k2;
- }
- LD F3 = (340000.0 * k3 / 2.0) / L;
- LD C3 = dist(F0, F3);
- if (C3 < bestC && k3 > 1)
- {
- bestC = C3;
- bestMask = mask;
- bestK = k3;
- }
- }
- for (int i = 0; i < n; i++)
- if (bestMask & (1 << i))
- cout << 'o';
- else
- cout << '.';
- cout << ' ' << bestK << ' ' << fixed << setprecision(8) << 12 * (log(bestC) / log(2.0)) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement