In this information-rich era, more and more people aspire to become internet celebrities and live streamers. As long as there is traffic, there will be endless endorsements and sponsorships. Wenwen, who loves living under the spotlight, wants to gain fame. The first step is to understand how the recommendation system of a popular video platform works. Here's an algorithm used by a certain video streaming platform. Let's help Wenwen better understand the video recommendation system!
When calculating the "priority recommendation index" on a certain video streaming platform, the information taken into account includes the number of viewers, the length of the video, the average viewing time, and the coefficient of relevance to the genre. The formula for the "priority recommendation index" is as follows:
Priority Recommendation Index = Number of Viewers * Average Viewing Time / Video Length * Coefficient of Relevance
Please list the recommended video names in descending order of the "Priority Recommendation Index."
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The first line contains a positive integer N (1 <= N <= 50), representing the number of videos. Following that are N lines, each containing a string S, a positive integer P, two positive integers L and W, and a positive integer R, separated by spaces.
- The string S (S contains no spaces, and the number of characters does not exceed 15) represents the video name. - The positive integer P (1 <= P <= 10^7) represents the number of viewers. - The positive integers L (1 <= L <= 180) and W (1 <= W <= 180) represent the video length and average viewing time (in minutes), respectively. - The positive integer R (1 <= R <= 10) represents the coefficient of relevance. | For each test case, output the video names in descending order of the "Priority Recommendation Index." (If the recommendation index is the same, output the videos in the order they were inputted). |
3 A-Fu 1000 4 4 9 HowHow 100 5 4 10 Married 1000 8 7 9 | A-Fu Married HowHow |
4 Mina 500 10 7 10 TT 400 5 4 7 CheerUp 420 3 2 6 Twice 900 3 2 5 | Mina Twice TT CheerUp |
Thought Process
Declare a Vector<Pair>, where the first field stores the recommendation index and the second field stores the negative of the input order (because after sorting, smaller numbers should be placed at the end for ties), and declare a Map, where the key is the input order and the value stores the string S.
After sorting the Vector, output from the last position to the first position. Take the negative of the second field and put it into the Map for output, using the resulting value as the Key, which represents string S.
Sample Code-ZeroJudge E800: Recommending Videos
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<pair<float, int>>num;
map<int, string>MAP;
for (int i = 0; i<N; i++)
{
string S;
float P, L, W, R;
cin >> S >> P >> L >> W >> R;
float calc = P * (W/L) * R;
pair<float, int>tmp;
tmp.first = calc;
tmp.second = i * -1;
num.push_back(tmp);
MAP[i] = S;
}
sort(num.begin(), num.end());
for (int i = int(num.size())-1; i>=0; i--)
{
cout << MAP[num[i].second * -1] << "\n";
}
}
//ZeroJudge E800
//Dr. SeanXD