Educational Codeforces Round 113 (Rated for Div. 2) C. Jury Meeting(思维 + 数学)

链接 C. Jury Meeting

题意

给出一组序列,每个元素依次减一,如果没有一个元素连续两次或者以上次数减一就说明这个序列是好的,求这个序列满足条件的序列数量;

思路

首先对于这个序列所有情况为 n ! n! n!
每个序列对于最大值进行三种情况的讨论:

  • 如果最大值个数大于 1 1 1 ,那这个序列就都是好的序列,直接输出 n ! n! n!
  • 如果序列中没有 m a x − 1 max-1 max1 这个数,那么直接输出 0 0 0,因为无论如何最大的数都会连续多次减一;
  • 如果最大值个数为 1 1 1,并且存在 m a x − 1 max - 1 max1 这个数,个数为 r e s res res ,那么当把 m a x − 1 max - 1 max1 放在最大值前边,然后对于剩余的数进行插入,那么不满足的情况就是 r e s ! ∗ ( r e s + 2 ) ∗ ( r e s + 3 ) . . . res! * (res + 2)*(res+3)... res!(res+2)(res+3)...;

AC代码

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
#include <queue>

#define x first
#define y second

using namespace std;

typedef long long ll;
const int N = 200010;
const ll mod = 998244353;

int T, n;
ll a[N];
ll b[N];

int main()
{
	b[1] = 1;
	for (int i = 2; i <= 2e5; i ++) {
		b[i] = b[i - 1] * i;
		b[i] %= mod;
	} 
	cin >> T;
	while (T --){
		cin >> n;
		ll ans = 1;
		for (int i = 1;i <= n ;i ++) cin >> a[i];
		sort(a + 1, a + n + 1);
		bool flag = false;
		int cnt = 0, res = 0;
		for (int i = n; i >= 1; i --){
			if (a[i] == a[n]) cnt ++;
			if (a[i] == a[n] - 1) res ++;
		}
		if (cnt != 1) {
			cout << b[n] << endl;
			continue;
		}
		if (!res) cout << 0 << endl;
		else {
			ll ans  = b[n];
			ll q = b[res];
			ll y = res + 2;
			for (int i = 1; i <= n - 1 - res; i ++)
			{
				q *= y;
				y ++;
				q %= mod;
			}
			ans += mod;
			ans -= q;
			ans %= mod;
			cout << ans << endl;
		}
		
	}
}

——END

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半碗无糖蓝莓冻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值