Codeforces 808D. Array Division】的更多相关文章

题目大意 给定你一个长为\(n\)的序列,问能否在最多一次取出某一元素然后插入到某一点后可以将整个序列分成两段使得其两段的元素之和相同. \(n \leq 10^5\) 题解 发现插入操作实际上是让某一个元素与端点周围的元素交换. 维护一个支持插入和查找元素是否存在的ds即可. #include <set> #include <cstdio> #include <cstring> #include <algorithm> using namespace st…
题目链接:http://codeforces.com/contest/808/problem/D 题意: 这一题给你一个数组,你可以调换某一个数的位置,使得这个数组可以分成2半,前半段的和等于后半段(严格的前半段和后半段).问你能不能构成. 题解: 一开始读题的时候,被吓坏了,没有看到是移动一个,因为题目在output那里才有写是移动一个. 那么如果这个和是奇数的话,就无法分成2个相等的部分.则是NO. 如果这个数列里有一个数是sum/2的话也是YES. 如果是移动一个数,那么这个数一定在某一个…
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecuti…
D. Array Division time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecuti…
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the seco…
题目链接:http://codeforces.com/contest/808/problem/D 题意:有一串长度为n的数组,要求选择一个数字交换它的位置使得这串数能够分成两串连续的和一样的数组. 这个数还可以和自己交换位置. 题解:很显然求一下前缀二分每个数看一下能否插入,再求一下后缀二分每个数看一下能否插入. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm…
传送门 题意 将n个数划分为两块,最多改变一个数的位置, 问能否使两块和相等 分析 因为我们最多只能移动一个数x,那么要么将该数往前移动,要么往后移动,一开始处理不需要移动的情况 那么遍历sum[i] 如果往前移动,sum[k]+(sum[i]-sum[i-1])=sum[n]/2,k∈[1,i-1] 如果往后移动,sum[k]-(sum[i]-sum[i-1])=sum[n]/2,k∈[i+1,n] 一开始我没有考虑往后移动 时间复杂度\(O(nlog(n))\) trick 代码 #incl…
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the seco…
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output a is an array of n positive integers, all of which are not greater than…
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between easy and hard versions is a number of elements in the array. You are given an array \(a\) consisting of \(n\) integers. The value of the \(i\)-th element…
You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array into kk non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let f(i)f(i) be the index of subarray th…
http://codeforces.com/problemset/problem/300/A 题意 :给你n个数字,让你分成3组,第一组各个数之积要小于0,第二组要大于0,第三组要等于0,符合要求的答案可能会有很多种,输出其中一种. 思路 :表示一开始以为要把n个数分成3组,第一组里的数都大于0这样子,所以一直卡在这儿....因为这个题也相当于special judge了吧,所以要找一个最不容易出错的输出,把n个数排序,最小的肯定是负的(题目保证至少有一个正确答案),所以直接把它分在第一组就行,…
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ ik < j…
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利用差分的思想,并且考虑到m比较小,遍历一遍序列,当前点遇到需要改变的时候进行操作,同时更新答案. #include <set> #include <map> #include <queue> #include <deque> #include <stack…
Array GCD 最后的序列里肯定有a[1], a[1]-1, a[1]+1, a[n], a[n]-1, a[n]+1中的一个,枚举质因子, dp去check #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #de…
题目链接: http://codeforces.com/problemset/problem/57/C 题意: 给你一个数n,表示有n个数的序列,每个数范围为[1,n],叫你求所有非降和非升序列的个数. 题解: 由于对称性,我们只要求非降序的个数就可以了(n个数全部相等的情况既属于非升也属于非降) 我们在满足条件的n个数之前加一个虚节点1,在第n个数之后加一个虚节点n,那么考虑这n+2个数组成的非降序列: 假设序列里的第i个数为a[i],我们设xi=a[i+1]-a[i]+1,1<=i<=n+…
http://codeforces.com/contest/808/problem/D 一开始是没什么想法的,然后回顾下自己想题的思路,慢慢就想出来了.首先要找到是否有这样的一个位置使得: 前缀和 == 后缀和,可以二分来求. 然后可以这样想,如果对于每一个数字,我都去移动一下,每个位置都试一下,复杂度多少?显然不能承受. 然后优化下这个思路,有了一点思路,优化到极致,看看能不能过,不能过就换思路吧.一般来说,每一个位置都试一下,是很没必要的.一般都是有一个位置是最优的. 这个位置就是放在最前或…
题目链接:http://codeforces.com/problemset/problem/300/A 题目意思:给出n个数,将它们分成三批:1.所有数相乘的结果 < 0    2.所有数相乘的结果 > 0:   3.所有数相乘的结果 = 0   还需要满足一个条件:n个数的归属只可以是其中的一批. 由于翻译的时候总是以整个短语来翻,因此一直误以为“product”是“产物”的意思,多谢乌冬兄指点迷津. 不难想到对所有数进行排序,最小的那个数绝对是负数,因此第一批数放1个即可:最大的那个数归到…
http://codeforces.com/contest/808/problem/D #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> #include<set> #include<map> #include<utility> usin…
题目链接: http://codeforces.com/contest/1108/problem/E2 题意: 给出$n$个数和$m$个操作 每个操作是下标为$l$到$r$的数减一 选出某些操作,使$n$个数的最大值减最小值最大 数据范围: $1 \le n \le 10^5$ $0 \le m \le 300$ $-10^6 \le a_i \le 10^6$ 分析: 假设选择第$i$位置作为最小值,那么我们选取所有包含$i$的区间可以得到选择第$i$位置为最小值的最佳答案 第一步,我们从$1…
output standard output The only difference between easy and hard versions is the number of elements in the array. You are given an array aa consisting of nn integers. In one move you can choose any aiai and divide it by 22 rounding down (in other wor…
B. Array K-Coloring time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output describe You are given an array a consisting of n integer numbers. You have to color this array in k colors in such a way th…
Codeforces 题面传送门 & 洛谷题面传送门 一道 hot tea--听讲解时半懂不懂因为不知道题目意思,最后终究还是琢磨出来了( 首先注意到对于每个 \(a_i\),它具体是什么并不重要,我们只关心它的奇偶性,因为每次到达一个点后,如果后手有必胜策略,那么如果先手原地踏步,那么后手完全可以重复先手的操作直到 \(a_i\lt 2\) 为止,如果先手有必胜策略则反过来.由于每次走到一个点时候都要令 \(a_i\) 减 \(1\),因此我们可以直接令 \(a_i\leftarrow (a_…
题目是给一些数和<数对>的下标,然后进行操作:对某个<数对>中的两个数同时除以一个都能被它们整除且不等于1的数,要求的就是最多能进行多少次操作. 除数一定是素数,就是要决定某素数要除哪些<数对>使除的次数最多, ik + jk is an odd number 可以想到这个是个二分图,数最多100个,然后就用最大流做了. 有了POJ2516的经验之后,马上想到,素数是独立的,进行若干次最大流而不是拆若干点跑最大流(109大概最多拆30个点吧).. 然后我还是没AC,因为…
思路:对于每个数分解质因子然后记录每一个质因子的个数,对与在b中出现的质因子就减去1,否则加1,求出总的,然后从后面一次对它们的最大公约数,然后判断除以最大公约数之后,改变量是不是变化,求最大值,变化量为负值的话减去. #include <cstdio> #include <cstring> #include <map> #include <set> #include <algorithm> using namespace std; set<…
主题链接:点击打开链接 的非增量程序首先,计算, 如果不增加的节目数量x, 非减少一些方案是x 答案就是 2*x - n 仅仅需求得x就可以. 能够先写个n3的dp,然后发现规律是 C(n-1, 2*n-1) 然后套个逆元就可以. #include<iostream> #include<cstdio> #include<vector> #include<string.h> using namespace std; #define ll long long #…
题意:给出一个数组,2种操作:.1:x*y然后x消失,2:除掉x(2操作最多只能进行一次).问最大的结果的一种操作方式.逻辑题,看能不能想全面. 1先数好0,正,负的数量,zero,pos,neg.如果0数量不为0,在所有0的内部用操作1减少到只剩1个0,zero置1:(删去0不影响结果,如果结果是0,那么剩1个0也能做到,如果结果不是0,那么删0是必须的) 2负数有奇数个时(这种情况下一定有非负解)(1)如果zero=0,用操作2删掉最大的负数(不删结果负,删了必为正)(2)zero=1,用0…
题意:给出一个序列,询问是否能移动一个数(或不操作)使得序列能分为左右两个和相等的子序列. 思路:对每个数处理最左边和最右边出现的位置.设置断点分左右区间,左右区间和差值的一半就是要找的数,进行判断. tip:很简单的想法,但debug很久很久,细节部分考虑欠妥.忘记位运算的优先级很低,sub&1==1错误,l[sub]<=i时漏考虑sub不出现时l[sub]都为0,发生错误. #include<bits/stdc++.h> using namespace std; typede…
题目传送门 题目大意:给出一个长度为n的数组,这个数组有的数是给出的,有的数是固定的,且范围都在[1,200]之间,要求这个数组中,每一个数字都小于等于 前后两个数字的最大值,求方案数mod p. 思路:一眼看出是个dp,但是不太擅长这个,看了大佬的题解,又加上了一些自己的思考. 由于这个数组每一个元素都是前后相关的,所以应该是个线性dp的东西,既然是线性的,我们就先考虑每一个元素和前面一个元素的关系(没法往后看,因为后面的元素都没有得到),将当前这个数字和前面的数字进行比较,会得到“>”“=”…
题意:给你一个长度为n的序列和m组区间操作,每组区间操作可以把区间[l, r]中的数字都-1,请选择一些操作(可以都不选),使得序列的最大值和最小值的差值尽量的大. 思路:容易发现如果最大值和最小值都在某个操作区间里,那么这个操作没有意义,因为差值没变,所以我们可以想到暴力枚举每一个位置,假设这个位置的数是最小的,那么就把所有与他相关的区间操作都执行,执行完后找到当前序列的最大值更新答案即可. E1数据很小,直接3重循环暴力枚举就可以过了,复杂度为O(n * n * m). 对于E2,很明显如果…