Educational Codeforces Round 118 ABCDE 题解 (Java/C++)

A. Long Comparison

题解

首先我们可以比较x的位数,如果位数不同,我们就对位数较少的数不断乘以10,直到位数相通。然后再比较调整后的p的大小。如果p一样,那么再比较x。

代码

Java

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

C++

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

B. Absent Remainder

题解

显然x mod y < x。因此我们将x永远选定为数组的最小值,然后y随便从剩下的数中选即可。

代码

Java

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

C++

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

C. Poisoned Dagger

题解

二分搜索k的值。每次按照题目描述计算总伤害即可。

代码

Java

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

C++

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

D. MEX Sequences

这个题目需要想清楚有那些构造方式。有了构造的方法dp就会显得比较显然。

Educational Codeforces Round 118 MEX Sequences 题解 (Java/C++)
题解首先我们考虑有那些选择方式可以满足条件。显然[0, 1, 2, 3, 4, 5]是符合条件的,因为对于任意的i,x[i]-MEX(x[1],..., x[i])=-1。同理,[0, 1, 2, 3, 4, 5, 5, ... ,5]也是满足条件的。
点击上面连接查看详细题解

E. Crazy Robot

题解

从L出发,dfs即可。每次寻找可能为+号的点,然后继续搜索即可。

而这个题目C++反而比Java容易TLE。因为n和m的值变动范围较大,而C++动态生成二维数组并初始化的速度似乎没有Java快。

代码

Java

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

C++

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