Untitled
unknown
c_cpp
5 months ago
1.8 kB
4
Indexable
#include <iostream> #include <string> #include <unordered_map> #include <algorithm> using namespace std; // Function to calculate the maximum beauty of a string after N rounds int calculate_max_beauty(const string& s, int N) { int M = s.size(); unordered_map<char, int> freq; // Calculate the frequency of each character in the string for (char c : s) { freq[c]++; } // Find the maximum frequency of any character in the string int max_freq = 0; for (const auto& [char_, count] : freq) { max_freq = max(max_freq, count); } // Calculate the potential maximum beauty after N changes // If all characters are already the same and N > 0, adjust for edge cases if (max_freq == M && N == 1) { return M - 1; // Can only decrease beauty in this case } return min(M, max_freq + N); // Maximum frequency is limited by the string's length } string solve(int N, int M, const string& P, const string& Q, const string& R) { // Calculate the maximum beauty for each string int bob_beauty = calculate_max_beauty(P, N); int ben_beauty = calculate_max_beauty(Q, N); int mike_beauty = calculate_max_beauty(R, N); // Determine the winner or if it's a draw if (bob_beauty > ben_beauty && bob_beauty > mike_beauty) { return "Bob"; } else if (ben_beauty > bob_beauty && ben_beauty > mike_beauty) { return "Ben"; } else if (mike_beauty > bob_beauty && mike_beauty > ben_beauty) { return "Mike"; } else { return "Draw"; } } int main() { // Input handling int N, M; string P, Q, R; cin >> N >> M >> P >> Q >> R; // Output the result cout << solve(N, M, P, Q, R) << endl; return 0; }
Editor is loading...
Leave a Comment