Educational Codeforces Round 113 (Rated for Div. 2) C. Jury Meeting

题目链接

  • 思路:

1.当拥有两个以上的最大值时,永远不会发生一个代表反复发言的情况

2.当有一个最大值时,如果没有max-1的话,没有答案,且有max-1的情况中max-1必须在max后面,所以最后的答案和max - 1的个数有关

3.总情况有n!种,减去不合法的情况即为答案,设max-1的个数为k,则有k*(k-1)种排列,放在max后面的有k种,剩下的(k-1)个数有(k-1)!种放法,所以为k!,对于剩下的n-k-1个没用的数字的位置,有种情况;乘上k!后,得到:,得到答案即为:

 

 

  •  代码:

 

#include <bits/stdc++.h>
#define ll long long

using namespace std;

typedef pair<ll, ll> PII;

const int N = 2e5 + 10, mod = 998244353;

int n;
ll a[N];

void solve()
{
    cin >> n;
    ll maxx = 0;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        maxx = max(a[i], maxx);
    }

    int cnt = 0;
    int cntm = 0;
    for (int i = 1; i <= n; i ++)
    {
        if(a[i] == maxx - 1) 
            cnt ++;
        if(a[i] == maxx)
            cntm ++;
    }

    ll ans = 1;
    ll base = 1;
    for (ll i = 1; i <= n; i ++)
    {
        ans = ans * i % mod;
        if(i != cnt + 1)  base = (base * i) % mod;
    }

    if(cntm == 1)
        cout << (ans - base + mod) % mod << endl;
    else cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    int T;
    cin >> T;
    while(T --)
    {
        solve();
    }
    return 0;
}

 

 

posted @ 2021-12-02 20:03  流氓丙土匪丁  阅读(22)  评论(0)    收藏  举报