题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数,要求偶数堆的个数为p. 输出方案. 解题思路:首先先将数组依照奇偶排序.也能够分开储存. 然后先单独分k-p个奇数,然后后面的就将两个奇数当一个偶数分配.分配过程中计算是否满足,比方说奇数是否成对,以及是否分成了k堆. #include <cstdio> #include <cstring…
题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; ],n,k,p; ]; ,ou=; int main() { memset(vis,,sizeof(vis)); cin >> n >> k >> p; ;i<n;i…
 Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came…
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:1 second     memory limit per test:256 megabytes Description Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interes…
题目 //参考了网上的代码 注意答案可能超过32位 //要达成目标,就是要所有数列a的都比数列b的要小或者等于 //然后,要使最小的要和最大的一样大,就要移动(大-小)步, //要使较小的要和较大的一样大,也是要移动(较大-较小)步 //然后都加在一起就好了 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; #def…
题意:给你n个数,然后分成k部分,每一个部分的和为偶数的有p个,奇数的有k-p个,如果可以划分,输出其中的一种,不可以输出NO; 思路:先输出k-p-1个奇数,再输出p-1个偶数,剩余的在进行构造.  奇数+奇数=偶数. #include <cstdio> #include <cstring> #include <vector> #include <iostream> #include <algorithm> #define maxn 10001…
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he ca…
Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came…
注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include <set> #include <algorithm> #include <cmath> using namespace std; int main(){ int n,k,p; long a; cin >> n >> k >> p; ve…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一开始所有的数字单独成一个集合. 然后用v[0]和v[1]记录集合的和为偶数和奇数的集合它们的根节点(并查集 然后先让v[0]的大小变成p //奇数+偶数是奇数 //奇数+奇数是偶数 //偶数+偶数是偶数 如果v[0].size < p 那么随便让两个和为奇数的集合,让他们合并在一起,加入到偶数集合中,那么v[0].size++,v[1].size-=2了 如果v[0].size > p 那么有两种方法  1.让两个偶数集合合…
题目链接:Codeforces 451E Devu and Flowers 题目大意:有n个花坛.要选s支花,每一个花坛有f[i]支花.同一个花坛的花颜色同样,不同花坛的花颜色不同,问说能够有多少种组合. 解题思路:2n的状态,枚举说那些花坛的花取超过了,剩下的用C(n−1sum+n−1)隔板法计算个数.注意奇数的位置要用减的.偶数的位置用加的.容斥原理. #include <cstdio> #include <cstring> #include <cmath> #in…
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列且最小. 思路 其实这题乱搞就行了.用到了之前HDdalao教我的素因子分解方法,可以快速地对枚举的数进行检测. 我们维护一个当前已填的数的素因子集合以及一个大于1的自然数集合(考虑最坏情况,我们总可以都用素数来构造这个序列.由素数的密度可知,n/ln(n)要大于1e5,所以该自然数集合上限达到2e…
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is to…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array…
Devu and Birthday Celebration 我们发现不合法的整除因子在 m 的因子里面, 然后枚举m的因子暴力容斥, 或者用莫比乌斯系数容斥. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pa…
Codeforces 1114 F 题意:给你一个序列\(a_{1\dots n}\),以及\(q\)次查询,每次查询有两种格式: TOTIENT \(l\) \(r\):求出\(\phi(\Pi_{i=l}^ra_i)\). MULTIPLY \(l\) \(r\) \(x\):将从\(l\)到\(r\)的所有数乘上\(x\leq 300\). 处理每次查询. 思路:首先我们知道设\(x=\Pi_{i=1}^np_i^{e_i}\),则\(\phi(x)=x\Pi_{i=1}^n\frac{p…
http://codeforces.com/contest/950/problem/D 前n/2个格子的奇数下标的数没有参与移动 候n/2个格子的奇数下标的数一定是一路移向偶数下标移 所以还原数的初始位置时,让数沿原来的路线向右移动,到达的第一个奇数下标就是这个数的初始位置 在初始位置a的数是(a+1)/2 现在就剩下了如何还原数向左移的过程 假设数a最后移到了位置x, 在位置x之前有 x/2 个奇数位有数 a移到了x,说明除了前面的数,剩下的数都在x之后 所以位置x之后有n-x/2-1 个数,…
题目链接:http://codeforces.com/problemset/problem/1006/C (CSDN又改版了,复制粘贴来过来的题目没有排版了,好难看,以后就截图+题目链接了) 题目截图: 题意:一个长度为n的数组,按顺序分成三部分,要求第一部分和第三部分元素的和相等(每一部分都可以没有元素,没有元素的部分元素和为0),求出第一部分和第三部分最大的相等的元素和,如果没有输出0 实现:开两个数组记录下数组的前缀和,后缀和(不知道这样叫对不对),然后用map记录下每个前缀和,后缀和指向…
一 题面 E. Minimum Array 二 分析 注意前提条件:$0 \le  a_{i} \lt n$ 并且 $0 \le  b_{i} \lt n$.那么,我们可以在$a_{i}$中任取一个数进行分析,发现为满足字典序最小,在$b$中找到$n-a_{i}$就是最优解. 接下来分析$b$,在$b$中是不一定找得到$n-a_{i}$的.所以需要分析如何找到此情况下的最优解. 假设$a_{i} = 3$,$n = 4$,那么$b_{i}$对应的最优情况是$b_{i} = 1$,可以把所有$b_…
http://codeforces.com/problemset/problem/439/C 题意:给你n个数,分成k个非空集合,其中有p个集合的元素和为偶数,其余k-p个集合的元素和为奇数. 思路:考虑两个数和的情况,奇+奇=偶,奇+偶=奇,偶+偶=偶.所以解决方案不存在的情况为 (oddnum<k-p || (oddnum-(k-p))%2!=0 || evennum+(oddnum-(k-p))/2<p). 先输出k-p-1组的单个奇数,输出p-1组偶数(先为单个偶数,偶数不够两个奇数)…
C. Good Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the arr…
题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. Amr d…
题目链接:http://codeforces.com/contest/572/problem/A 题意 就给你两个数组,问你能不能从A数组中取出k个,B数组中取出m个,使得这k个都大于这m个. 题解 就模拟 代码 #include<iostream> #include<cstring> #include<algorithm> #define MAX_N 100005 using namespace std; int n0,n1; int k,m; int a[MAX_N…
题目链接:https://codeforces.com/contest/1367/problem/B 题意 有一大小为 $n$ 的数组 $a$,问能否经过交换使所有元素与下标奇偶性相同(0 - indexed). 题解 奇偶性不同的奇数和偶数个数应相等. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int odd = 0, even = 0; for (int i…
题意:有n个瓶子每个瓶子有 f[i] 支相同的颜色的花(不同瓶子颜色不同,相同瓶子花视为相同) 问要取出s支花有多少种不同方案. 思路: 如果每个瓶子的花有无穷多.那么这个问题可以转化为  s支花分到n个瓶子有多少种方案  用隔板法就能解决 C(s+n-1,n-1) .有限制之后我们可以 用 没限制的去减掉那些违反限制的 如果只有一个瓶子取得花超出上限 那么减去,两个瓶子 要加上(容斥原理) n只有20  就能暴力枚举那些取超过上限f[i]的瓶子并且在这些瓶子至少选出 f[i]+1 支花  统计…
题目地址 在WFU(不是大学简称)第二次比赛中做到了这道题.高中阶段参加过数竞的同学手算这样的题简直不能更轻松,只是套一个容斥原理公式就可以.而其实这个过程放到编程语言中来实现也没有那么的复杂,不过为了让计算机在限定的时间内完成计算需要进行一些对计算上的优化.模MOD的情况下计算组合数nCr只需要求出分子再乘以分母的逆元,考虑到模的是1e9+7本身就是一个质数,根据费马小定理a^(MOD-2)即是a在模MOD意义下的逆元.求逆元的时候为了节约计算时间可以采用快速幂.计算过程就是容斥原理,就没有什…
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的按位与和至少为多少. 更新时,如果val的pos位为1,那么整个区间的按位与和pos位也应该为1,否则与出来就不对了.(这是本题解题的核心) 那么此时更新 sum[rt] |= val 即可.然后再check一遍看是否满足所有条件即可. 代码: #include <iostream> #inclu…
题目链接:点击打开链接 = - =曾经的三分姿势不对竟然没有被卡掉,,,太逗.. #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #include<cstdio> #include<set> #include<map> #include<vector> #include<cstring> #inclu…
题目链接 给n个盒子, 每个盒子里面有f[i]个小球, 然后一共可以取sum个小球.问有多少种取法, 同一个盒子里的小球相同, 不同盒子的不同. 首先我们知道, n个盒子放sum个小球的方式一共有C(sum+n-1, n-1)种, 但是这个题, 因为每个盒子里的小球有上限, 所有用刚才那种方法不行. 但是我们可以枚举. n只有20, 一共(1<<20)-1种状态, 每种状态, 1代表取这个盒子里的小球超过了上限, 0代表没有. 一共取sum个, 如果一个盒子里面的小球超过了上限, 那么就还剩下…
题意:b数组可以自由排序,c[i]=(a[i]+b[i])%n. 题目中要求c数组的字典序是最小的.那么我们需要尽量满足前面的c[i],才能使字典序最小. 我们知道a[i]和b[i]都是[0,n-1]的范围内.那么我们容易得到 如果a[i]+b[i]>=n,(a[i]+b[i])%n<a[i]且(a[i]+b[i])%n<b[i].得出这样的结论之后,我们就可以进行模拟了. 如果当前a[i]能找到一个b[i]使得a[i]+b[i]>=n,那么我们就找符合条件最小的元素,否则的话a[…