首页 > 其他分享 >CF1753B 题解

CF1753B 题解

时间:2022-12-23 14:33:26浏览次数:54  
标签:cnt const int 题解 long CF1753B include define

\(\mathcal Preface\)

题目传送门

\(\mathcal Solution\)

定理:\(n! \cdot (n+1) = (n+1)!\)

这题就是围绕以上定理展开的。

如果加入一个数 \(a_i\) 满足 \(\operatorname{count}(a_i) > a_i\),则根据定理,将 \(\operatorname{count}(a_{i+1}) + 1\),在将 \(a_i=0\)。其中 \(\operatorname{count}(a_i)\) 表示 \(a_i\) 出现的次数

如果 \(\sum\limits_{i=1}^{n}a_i! \mid x!\) 即满足 \(\left(\sum\limits_{i=1}^{x-1}\operatorname{count}(i)\right) = 0\)。

\(\mathcal Code\)

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
#include <sstream>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false)
#define cit cin.tie(0)
#define cot cout.tie(0)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 500010, M = 100010, MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int n, x;
int cnt[N];

void solve()
{
	cin >> n >> x;
	for (int i = 1; i <= n; i ++ )
	{
		int t;
		cin >> t;
		cnt[t] ++ ;
		while (cnt[t] >= t + 1)
		{
			cnt[t + 1] += cnt[t] / (t + 1);
			cnt[t] %= (t + 1);
			t ++ ;
		}
	}
	
	bool flag = true;
	for (int i = 1; i < x; i ++ )
		if (cnt[i])
		{
			flag = false;
			break;
		}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main()
{
	IOS;
	cit, cot;
	int T = 1;
//	cin >> T;
	while (T -- ) solve();
	return 0;
}

标签:cnt,const,int,题解,long,CF1753B,include,define
From: https://www.cnblogs.com/hcywoi/p/17000606.html

相关文章

  • Python从入门到精通(第2版)——pyuic5: error: no such option: -m的问题解决
    前言在学习《Python从入门到精通(第2版)》的第15章GUI界面编程——15.2.4将.ui文件转换为.py文件时,按照书中步骤出错时的问题解决,希望对同样学习本书的同学有所帮助。问......
  • [省选联考 2021 B 卷] 数对 题解
    题目描述给定\(n\)个正整数\(a_i\),请你求出有多少个数对\((i,j)\)满足\(1\lei\len\),\(1\lej\len\),\(i\nej\)且\(a_i\)是\(a_j\)的倍数。提示对于......
  • chrome使用拖拽本地扩展时无法安装的问题解决办法
    在使用Chrome拖拽安装本地扩展时会提示无法安装,可以采用以下两个方法解决1、修改.crx文件文件格式为zip,并进行解压,然后打开扩展安装界面的开发者模式,使用加载已解压的扩展......
  • Codeforces 1654 G Snowy Mountain 题解 (重心分治)
    题目链接假设现在起点已经确定,我们观察从这个起点开始能走的最长路径长什么样。把这条最长路径中所有的非平地路径拿出来,它们肯定连成一线,因为不允许上坡;而一条路径重复走......
  • luoguP2254 [NOI2005]瑰丽华尔兹 题解
    传送门题意给定\(n\)行\(m\)列的矩阵和钢琴的初始位置\((x,y)\),给定\(k\)个时间段,在每个时间段内钢琴会向给定方向(上/下/左/右)滑动,\(1\)秒移动\(1\)个单位长度......
  • 问题解决1
      出现这样的问题需要导入jar包 ......
  • 洛谷 P5401 [CTS 2019] 珍珠 题解
    题目链接令\(c_i\)表示第i种颜色的珍珠的数量,显然我们最多能装的瓶数是\(\sum\lfloor\frac{c_i}2\rfloor\)。也就是说,\(c_i\)为奇数的\(i\)的数量不能太多,这个数量要......
  • MEGAN V2.10 的pgf90编译器安装以及相关问题解决
    这里列出了一些MEGAN安装中可能遇到的一些问题,分享出我自己的一些解决方法。pgf90编译器的下载:目前PGI已经被整合到NVIDA官方cuda,所以只能直接下载整个到linux中:https:/......
  • [USACO18OPEN] Talent Show G 题解
    [USACO18OPEN]TalentShowG想法同样是01分数规划。思路先假设一个不够好的答案\(mid\),则原答案可表示为\[\dfrac{\sumt_i}{\sumw_i}(\sumw_i\geqW)\]我们先......
  • [USACO07DEC]Sightseeing Cows 题解
    题目描述[USACO07DEC]SightseeingCows给定一张\(L\)个点、\(P\)条边的有向图,每个点都有一个权值\(f[i]\),每条边都有一个权值\(t[i]\)。求图中的一个环,使“环上各......