首页 > 其他分享 >CF1753B 题解

CF1753B 题解

时间:2022-10-24 21:35:13浏览次数:71  
标签:cnt ++ 题解 times CF1753B int 进位

前言

题目传送门!

更好的阅读体验?

其实挺简单的,赛时多打了个等号,被人叉了。

思路

关键是 \(n! \times (n + 1) = (n + 1)!\)。

原因很显然:\((1 \times 2 \times \cdots \times n) \times (n + 1) = (n + 1)!\)。

知道这个,这道题不就做完了吗。统计每一个数码的个数,每次能进位就进位(指 \((n + 1)\) 个 \(n!\) 进出一个 \((n + 1)!\))。

要求成立,当且仅当 \(1\) 至 \((x - 1)\) 都进没了,只有 \(x\) 的桶里有数。

具体看代码吧,非常容易理解。

代码

//赛时代码
#include <bits/stdc++.h>
using namespace std;
int cnt[500005];
int main()
{
	ios::sync_with_stdio(false);
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		cnt[a]++; //统计
	}
	for (int i = 1; i < x; i++) cnt[i + 1] += (cnt[i] / (i + 1)), cnt[i] %= (i + 1); //"进位"
	for (int i = 1; i < x; i++)
		if (cnt[i])
		{
			cout << "No";
			return 0;
		}
	if (cnt[x]) cout << "Yes";
	else cout << "No";
	return 0;
}

希望能帮助到大家!

标签:cnt,++,题解,times,CF1753B,int,进位
From: https://www.cnblogs.com/liangbowen/p/16823055.html

相关文章

  • [abc262E] red and blue gragh 题解
    挺喜欢这道题的,但是因为vp时过了不能写成做题笔记,所以只能写成题解了。绿太配这道题了,实现难度极低,但思维难度较大。AT评了#1719,倒也算恰当。题意:给定一张\(n\)点......
  • 「ARC151E」Keep Being Substring - 题解
    题意题目链接:Link。有一个序列\(A\)。\(X,Y\)是给定的\(A\)的两个子串,每次可以在\(X\)的开头或末尾增添或删除一个数字,且需满足任意时刻\(X\)非空且为\(A\)的......
  • [abc274F] Fishing 题解
    比较有趣的用点思维的题。在学校和DYS一起推出来的题,庆祝AT复活写个题解。感觉用无序列表列出自己思绪的过程很简洁扼要,但是行文节奏过快。介于我想重现自己今天上午......
  • 「ARC140D」One to One - 题解
    题解若对每一块进行考虑,那么对于一个有\(n\)个点\(n\)条边的块,也就是基环树或环来说,里面一定不会存在\(a_i=-1\)。否则就是一棵树了,那么也最多只会有一个\(a_i=-1\)......
  • [NOI Online #1 入门组] 跑步 题解
    [NOIOnline#1入门组]跑步题解一个经典问题:计数将正整数\(n\)拆分为若干个正整数的方案数,这里拆成的正整数是无序的,对\(P\)取模。容易得到\(O(n^2)\)解法设\(f_{i,j......
  • Codeforces Round #401 (Div. 2) 题解 (待续)
    AShellGame#include<bits/stdc++.h>usingnamespacestd;#define#define#define#define#define#define#define#define#define#define#define#define#define#define#define......
  • April Fools Contest 2017 题解
    ANumbersJokeJoke数列,OEIS#include<bits/stdc++.h>usingnamespacestd;#define#define#define#define#define#define#define#define#define#define#define#define#define......
  • Codeforces Round #402 (Div. 1) 题解(待续)
    AStringGame#include<bits/stdc++.h>usingnamespacestd;#define#define#define#define#define#define#define#define#define#define#define#define#define#define#defin......
  • BZOJ 4747-4749题解 Usaco2016 Dec
    BZOJ4747:[Usaco2016Dec]CountingHaybales给出N(1≤N≤100,000)个数,和Q(1≤Q≤100,000)个询问。每个询问包含两个整数A,B(0≤A≤B≤1,000,000,000)。对于每个询问,给出数值......
  • Codeforces Round #395 (Div. 1) 题解
    ATimofeyandatree#include<bits/stdc++.h>usingnamespacestd;#define#define#define#define#define#define#define#define#define#define#define#define#define#defin......