题目链接:https://codeforces.com/contest/1417/problem/A 题意 给出一个大小为 $n$ 的数组 $a$,每次操作可以选择两个数,然后将一个数加到另一个数上,要求操作后的数不能大于 $k$,问最多可以操作多少次. 题解 除一个最小值外,给每个数一直加最小值. 证明 操作的本质是留下哪一个数,明显留下较小的数更优. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::syn…
题意:给你一组数\(a\)和一个数\(T\),将这组数分为两组\(c\)和\(d\),定义\(f(x)\)为数组\(x\)中任意两个不同元素的和为\(T\)的个数,问为了使\(min(f(c)+f(d))\),应该怎样对\(a\)分组. 题解:我们可以分成三种情况,假如一组数中所有元素都\(< \frac{T}{2}\),或者\(>\frac{T}{2}\),那么它们的\(f(x)\)都为\(0\),然而对于\(a[i]=\frac {T}{2}\)的情况,我们将其交叉放在两组即可. 代码:…
[Codeforces Round #673 (Div. 2) ] 题目链接# A. Copy-paste 思路: 贪心的策略.每次只加上最小的就可以了 #include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; typedef long long ll; ll a[1010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);…
题目链接:https://codeforces.com/contest/1417/problem/B 题意 定义 $f(a)$ 为数组 $a$ 中满足: $i < j$ $a_i + a_j = T$ 的二元组 $(i,j)$ 的个数. 试将一个大小为 $n$ 的数组 $a$ 划分为 $b,c$ 两组,使得 $f(b) + f(c)$ 最小. 题解 两数之和为 $T$ 有两种情况: 一个数小于 $T$,一个数大于 $T$,此时以 $\frac{T}{2}$ 为分界线分到两组即可 两个数都等于 $…
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 $k$ 长区间中出现的数的最小值. 题解 记录一个值两两间的最大距离,该距离的 $k$ 长区间及之后更长的区间都可能以该值为最小值. Tips 注意两端的处理. 代码一 #include <bits/stdc++.h> using namespace std; int main() { ios:…
题目链接:https://codeforces.com/contest/1417/problem/D 题意 给出一个大小为 $n$ 的正整数数组 $a$ ,每次操作如下: 选择 $i,j$ 和 $x$,$(1 \le i, j \le n,\ 0 \le x \le 10^9)$ 令 $a_i - x \cdot i,\ a_j + x \cdot i$ 要求过程中不能有负数产生,问能否在 $3n$ 次操作内使数组中的每个元素相等,如果可以给出操作次数和过程. 题解 把每个 $a_i$ 变为 $…
题意:有一组数,分别用长度从\([1,n]\)的区间去取子数组,要求取到的所有子数组中必须有共同的数,如果满足条件数组共同的数中最小的数,否则输出\(-1\). 题解:我们先从后面确定每两个相同数之间的距离,然后维护每个\(i\)位置上的数到后面所有相同数的最大距离,然后我们就可以dp来搞了,我从\(1\)开始遍历,如果\(a[i]\)后面的所有相同数间隔的最大距离不大于\(k\),那么说明这个数是满足长度为\(i\)的区间的,我们更新状态\(dp[i]=min(a[i],dp[i])\),否则…
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova's house is an array consisting of nn elements (yeah, this is the first probl…
D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number.…
A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th blo…