AT3589 Similar Arrays 题解】的更多相关文章

Content 给定一个长度为 \(n\) 的序列 \(a\).定义两个序列 \(x,y\) 是相似的,当且仅当 \(\forall i\in[1,n],|x_i-y_i|\leqslant 1\).请你求出有多少个序列 \(b\),使得: 序列 \(a,b\) 相似. 序列 \(b\) 的所有数的乘积为偶数. 数据范围:\(1\leqslant n\leqslant 10\),\(1\leqslant a_i\leqslant 100\). Solution 根据题意我们不难发现,对于序列 \…
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these…
Content 给定两个长度分别为 \(n\) 和 \(m\) 的数列 \(A,B\).你需要将两个数列都恰好分成 \(k\) 份,使得两个数列中第 \(i(i\in[1,k])\) 份的元素和对应相等.问是否可行,并在可行的情况下求出最大的 \(k\). 数据范围:\(1\leqslant n,m\leqslant 3\times 10^5\),\(1\leqslant A_i,B_i\leqslant 10^9\). Solution 我们先将两个数列中的所有数的和加起来,记为 \(S_A,…
Professor GukiZ and Two Arrays 题解: 将a数组都sort一遍之后, b数组也sort一遍之后. 可以观察得到 对于每一个ai来说, 整个数组bi是一个V型的. 并且对于ai+1的最优解一定是在ai的右边. 然后我们将a数组 和 b数组枚举一遍. 然后再将a数组22组合, b数组22组合之后, 再枚举一遍. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_i…
CF915G Coprime Arrays 题解 (看了好半天终于看懂了) 我们先对于每一个i想,那么 我们设 我们用莫比乌斯反演 有了这个式子,可比可以求出△ans呢?我们注意到,由于那个(i/d)是下取整了的,所以i++后(下文的 i 是+1后的 i),只有当(d+1)|i 时答案有变化,于是 我们可以预处理a^n,以及用埃氏筛预处理△ans[i] CODE #include<cstdio> #include<cstring> #include<vector> #i…
前言 有一场下午的cf,很滋磁啊,然后又和dalao(见右面链接)组队打了,dalao直接带飞我啊. 这是一篇题解,也是一篇总结,当然,让我把所有的题目都写个题解是不可能的了. 按照开题顺序讲吧. 在开始前有现场赛的成绩,所以可以看出来哪道是傻逼题,当然还是滋磁啊. M - The Pleasant Walk 我被分到了这道题,当然是因为我太弱了啊,dalao当然是要去做神仙题了. 好像没什么可说的了,直接扫不就行了.. #include<cstdio> #include<cstring…
A - Can you get AC? No #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define pb push_back #define mp make_pair using namespace std; typedef long long int64; char s[15]; int main() { scanf("%s",…
A. Company Merging Solved. 温暖的签到. #include<bits/stdc++.h> using namespace std; ; typedef long long ll; struct node{ int val, num; node(){} node(int val, int num):val(val), num(num){} }arr[maxn]; int n, m; int main() { while(~scanf("%d", &a…
Hash Table基础 哈希表(Hash Table)是常用的数据结构,其运用哈希函数(hash function)实现映射,内部使用开放定址.拉链法等方式解决哈希冲突,使得读写时间复杂度平均为O(1). HashMap(std::unordered_map).HashSet(std::unordered_set)的原理与Hash Table一样,它们的用途广泛.用法灵活,接下来侧重于介绍它们的应用. 相关LeetCode题: 706. Design HashMap  题解  705. Des…
排序基础 排序方法分两大类,一类是比较排序,快速排序(Quick Sort).归并排序(Merge Sort).插入排序(Insertion Sort).选择排序(Selection Sort).希尔排序(Shell Sort).堆排序(Heap Sort)等属于比较排序方法,比较排序方法理论最优时间复杂度是O(nlogn),各方法排序过程和原理见  可视化过程. 另一类是非比较排序,被排序元素框定范围的前提下可使用非比较排序方法,例如桶排序(Bucket Sort).计数排序(Counting…