cf754 A. Lesha and array splitting】的更多相关文章

应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了) #include<bits/stdc++.h> #define lowbit(x) x&(-x) #define LL long long #define N 200005 #define M 1000005 #define mod 2147483648LL #define inf 0x7ffffffff using namespace std; inline int ra() { ,f=; char ch=getchar(); ;…
A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts.…
题目链接 Lesha and array splitting 设s[i][j]为序列i到j的和,当s[i][j]≠0时,即可从i跳到j+1.目标为从1跳到n+1,所以按照题意暴力即可. #include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i(a); i <= (b); ++i) #define dec(i,a,b) for(int i(a); i >= (b); --i) + ; stru…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split…
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的数,只要有一个不为0的数,那么就能分割. 如果一个数不为0,则让它单独成为一组,如果它后面有0,则把它后面的连续的0也归到这一组中. 特别要注意一下的是,序列一开始就是0的情况. #include<iostream> #include<algorithm> #include<cs…
C. Array Splitting You are given a sorted array…
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…
You are given an array…
题目链接 题意 给出一个长度为\(n\)的序列\(a\),要求分为恰好\(K\)段.第\(i\)个点的贡献是\(a_i \times f(i)\),\(f(x)\)表示x所属的是第几段. 思路 非常巧妙的一个思路. 先让每个元素都选K遍.然后不断的删除. 具体做法就是,先求一遍前缀和.然后找出前缀和最小的\(K-1\)个前缀,将其从答案中减去.初始答案为所有元素和\(\times K\) 这样被减j遍的元素就位于第\(K-j\)段中.因为是前缀和.所以前边点被减的次数一定大于等于后边.然后就符合…
新鲜热乎的题 Codeforce 1175 D. 题意:给出一个长度为$n$的序列$a$,你需要把它划分为$k$段,每一个元素都需要刚好在其中一段中.分好之后,要计算$\sum_{i=1}^{n} (a_i \centerdot f(i))$,使这个值最大.其中$f(i)$代表第$i$个元素被分在第几段中.简单来说,就是每个元素被分在第几段中就需要乘上几,使序列的和最大. 假设$sum$是$a$的前缀和,$k$个分割点分别为$l_j$,将序列分割为$[1, l_1],[l_1 + 1, l_2]…