CSP-J semi-finals sprint must-answer questions | P7072 Live broadcast to win the prize

Learn C++ from a young age! Record the questions in the CSP-J exam preparation study process and record every moment.

Attached is a summary post: CSP-J semi-final sprint must-answer questions | Summary_Blog of a communicator who loves programming-CSDN Blog


[Title description]

NOI2130 is coming soon. In order to increase the viewing pleasure, CCF decided to evaluate the results of each player one by one and broadcast the real-time winning score line live. The winning rate of this competition is  w %, that is, the lowest score of the top  w % of players is the immediate score line.

More specifically, if the results of p  players have been evaluated currently  , the current planned number of winners is max(1,⌊ p × w %⌋), where  w  is the winning percentage, and ⌊ x ⌋ means   rounding down x , max( x , y ) represents   the larger number between x  and  y . If there are players with the same results, all players with tied results will be awarded, so the actual number of winners may be more than planned.

As a technical member of the evaluation team, please help CCF write a live broadcast program.

【enter】

The first line has two integers  n and w . Represent the total number of players and winning rate respectively. The second line contains  n  integers, which in turn represent the scores of the players evaluated one by one.

【Output】

There is only one line, containing  n  non-negative integers, which in turn represent the immediate winning scores after the players' scores are evaluated one by one. Two adjacent integers are separated by a space.

【Input sample】

10 60
200 300 400 500 600 600 0 300 200 100

【Output sample】

200 300 400 400 400 500 400 400 300 300

[Detailed code explanation]

#include <bits/stdc++.h>
using namespace std;
int n, w, x;
int s[1000];
int main()
{
    cin >> n >> w;
    for (int i=1; i<=n; i++) {
        cin >> x;
        s[x]++;
        int t = max(1, i*w/100);
        int sum = 0;
        for (int j=600; j>=0; j--) {
            sum += s[j];
            if (sum>=t) {
                cout << j << " ";
                break;
            }
        }
    }
    return 0;
}

【operation result】

10 60
200 300 400 500 600 600 0 300 200 100
200 300 400 400 400 500 400 400 300 300

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/133465045