Codeforces Round #726 ABCD 题解 (Java/C++)

A. Arithmetic Array

题解

对于和小于n的,则我们只需要补1个数字使得和等于n。

对于和大于n的,那么我们通过补充若干个0,使得n等于所有数字之和。

代码

Java

Submission #119949433 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #119949649 - Codeforces
Codeforces. Programming competitions and contests, programming community

B. Bad Boy

题解

不论初始位置在哪里。其结果一定是两个对角。因此输出1 1 n m即可。

代码

Java

Submission #119951740 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #119951848 - Codeforces
Codeforces. Programming competitions and contests, programming community

C. Challenging Cliffs

题解

对高度进行排序后,可以选择差最小的两个相邻数作为一头一尾。

为了开销最高,因此应当尽可能的保持数组单增。因此可按下图操作:

代码

Java

Submission #119956263 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #119956445 - Codeforces
Codeforces. Programming competitions and contests, programming community

D. Deleting Divisors

突破口是初始值为奇数,因为奇数只能转化为偶数。进而将初始值划分成三类,并推出其转移方式即可。

Codeforces Round #726 Deleting Divisors 题解 (Java/C++)
题解我们将数字分成三类:奇数、不包括$2^n$在内的偶数,以及$2^n$。于是,经过一步操作我们发现三类数字会有如下转化:

最近太累了,E题F题虽然都不够2500。但是之后再补吧。