Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

链接:

https://codeforces.com/contest/1265/problem/C

题意:

So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved pi problems. Since the participants are primarily sorted by the number of solved problems, then p1≥p2≥⋯≥pn.

Help the jury distribute the gold, silver and bronze medals. Let their numbers be g, s and b, respectively. Here is a list of requirements from the rules, which all must be satisfied:

for each of the three types of medals, at least one medal must be awarded (that is, g>0, s>0 and b>0);
the number of gold medals must be strictly less than the number of silver and the number of bronze (that is, g<s and g<b, but there are no requirements between s and b);
each gold medalist must solve strictly more problems than any awarded with a silver medal;
each silver medalist must solve strictly more problems than any awarded a bronze medal;
each bronze medalist must solve strictly more problems than any participant not awarded a medal;
the total number of medalists g+s+b should not exceed half of all participants (for example, if n=21, then you can award a maximum of 10 participants, and if n=26, then you can award a maximum of 13 participants).
The jury wants to reward with medals the total maximal number participants (i.e. to maximize g+s+b) so that all of the items listed above are fulfilled. Help the jury find such a way to award medals.

思路:

直接找到不相等的位置,满足条件即可。

代码:

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 4e5+10;
 
int a[MAXN];
int n;
 
int main()
{
    // freopen("test.in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        bool flag = true;
        cin >> n;
        for (int i = 1;i <= n;i++)
            cin >> a[i];
        int i = 2;
        for (i = 2;i <= n;i++)
        {
            if (a[i] != a[i-1])
                break;
        }
        int m = n/2;
        if ((m-(i-1))/2 <= (i-1))
            flag = false;
        int j;
        for (j = m;j >= i;j--)
        {
            if (a[j] > a[j+1])
                break;
        }
        int k = -1;
        for (int ii = i+1;ii <= j;ii++)
        {
            if (a[ii] < a[ii-1] && ii-i > i-1)
            {
                k = ii;
                break;
            }
        }
        if (k == -1)
            flag = false;
        if (i-1 >= k-i || i-1 >= j-k+1)
            flag = false;
        if (!flag)
            cout << "0 0 0" << endl;
        else
            cout << i-1 << ' ' << k-i << ' ' << j-k+1 << endl;
        
    }
 
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/YDDDD/p/12000243.html