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

A. Find Array

题解

显然,当x>0时,x不能被x+1整除。因此我们令a[i]=a[i-1]+1即可。

代码

Java

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

C++

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

B. Build the Permutation

题解

首先a和b的差异不能超过1。从下图中我们可以看出要链接两个“a”(蓝色),必须要有一个“b”才行(红色):

构造方式如下图所示:

$a \geq b$
a<b

代码

Java

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

C++

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

C. Game Master

题解

首先,对于如果某个人在某张图拥有最大的力量,那么他一定有可能胜利。

而如果一个人可能胜利,那么如果另外一个人如果能在某张图上打败这个人,那么另外的这个人可能胜利。

于是我们直接递归即可。

代码

Java

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

C++

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

D. Dominoes

这个题的关键是发现WB和BW在大多数情况下放在任何地方都可以。

Codeforces Round #758 Dominoes 题解 (Java/C++)
题解首先,我们需要注意到的是,多米诺牌涂色后其实就只有4种状态:BW,WB,WW,BB。于是我们自然的开始考虑如何构造一个有效的涂色方法。不难发现,最终的构造方案一定形如:BB, WB, WB, ..., WB, WW, BW, BW, ..., BW, BB, WW, BB, WW。
点击上面链接查看详细题解